C++ Freeglut Run-Time Check Failure #2 - S, Visual Studio C++


My game engine dies when i run my app.

When i run app this message pops out:Run-Time Check Failure #2 - S

when i click dismiss the app stops working.

Here's my code snippet

:(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "pch.h"
#include <iostream>
#include "glut.h"

#include "conio.h"
using namespace std;

#include<stdio.h>
#include "bmp_loader.h"
#include "map_loader.h"
#include "models.h"
#include "IEDX_POLYTEX.h"
#include "FONTGER/include/fontmann.h"
#define KEY_ESC 27 /* GLUT doesn't supply this */
#pragma comment(lib, "GLAUX_iedx_fonts.lib")
...
void Display(){
...
    GLuint my_texturec[13] = { 0xffaec900, 0x0000ffae, 0xc9ffaec9,
        0xffaec9ff, 0xaec90000, 0x00ffaec9,
        0x000000ff, 0xaec9ffae, 0xc9000000,
        0xffaec900, 0x00000000, 0x00ffaec9 }
        ;

  	glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
		GL_RGB8, GL_UNSIGNED_BYTE, my_texturec);
	glGenTextures(34, my_texturec);
	glBindTexture(GL_TEXTURE_2D,  34);
	LoadMap(3);
...
}
...
Last edited on
It sounds like Visual Studio is doing debug runtime checks. It might be that you're trying to access an array out of bounds.

Visual Studio has a great debugger -- use it, and step by your code line by line so you can figure out exactly where the error is occurring.*

______________________

About your OpenGL calls:
• Why are you using 34 as a magic number? Do you have 34 textures? Looks like you have 13 slots allocated for textures.
• Why are you filling in random numbers for 12 of these textures? They are overwritten by glGenTextures anyway.
• Why are you trying to use my_texturec before calling glGenTextures?
• glTexImage2D expects pixel data as the last parameter, not an array of texture IDs. It seems that you're conflating texture ids with pixel data or something.
• You're definitely using glBindTexture wrong, you should be using your texture id as the second parameter.
• And binding should happen before glTexImage2D is called.

*If OpenGL calls are what are failing for you, call glGetError!
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetError.xhtml
https://blog.nobel-joergensen.com/2013/01/29/debugging-opengl-using-glgeterror/


To other forumers: Question was also posted here, and has an answer
https://stackoverflow.com/questions/58185351/c-freeglut-run-time-check-failure-2-s-visual-studio-c
Last edited on
Topic archived. No new replies allowed.