Skip to main content
GameDev.net gamedev.net
🔒 Locked

Strange C++ issue ?

Started by Renran Feb 13, 2010 at 7:07 AM 7 replies 2.1k views
Original Post
Renran
Renran
Hello, Trying to make a game but having a strange issue with VC++: Using VC++, SDL, Opengl. I make a global array: char Map[100]; Then running the editor in a window starting up, Map[100] got filled with 0's from a file. Somewhere else I have a key(toggle) where I can change to fullscreen and back to window: case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_l){ windowreshape++; if (windowreshape == 1){SDL_SetVideoMode(window_width, window_height, bpp, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWSURFACE | SDL_FULLSCREEN); // setting up Gl GL_Setup(window_width, window_height);} if (windowreshape == 2){SDL_SetVideoMode(window_width, window_height, bpp, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWSURFACE); // setting up Gl GL_Setup(window_width, window_height); if (windowreshape == 2) windowreshape=0; } Toggling from fullscreen to window. But when to program starts map[]= filled with 0's After a toggle map[] is filled with all kind of values and it stays that way with all next toggles. But always the same strange values even after a new start en toggle. There are even floating point values but I'm using a only a "char" here. map[] has nothing to do with changing screens. What is happening here???? Memory leak???? Anyone? Thanks, RenRan
rip-off
rip-off
What does "GL_Setup" do? Your problem sounds like memory corruption.
Renran
Renran
void GL_Setup(int width, int height)
{
float ambientLight[]={5.5,5.5,5.5,1.0};
//glClearColor(0.0,0.0,0.2,1.0);
glClearDepth(1.0);
glEnable( GL_DEPTH_TEST );
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity ();
gluPerspective( 70.0f, (float)width/height, 0.1, 1000.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity ();
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glShadeModel (GL_FLAT);
glEnable(GL_LIGHTING);
// glEnable(GL_LIGHT0);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientLight);
// glLightfv(GL_LIGHT0, GL_POSITION, white);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_POLYGON_SMOOTH);

+ loading a lot of bmp textures with "AUX_RGBImageRec"

}

RenRan
rip-off
rip-off
Have you tried stepping through the code in a debugger to pinpoint exactly when values being to be written to "map". Also, the calls to AUX_RGBImageRec sounds like the kind of place where one could overrun an array, which might explain your problem.
Wan
Wan
Unrelated to the map issue I assume, but this looks a little redundant (unless the setup function causes a side effect that changes a globally defined windowreshape variable):
if (windowreshape == 2){  SDL_SetVideoMode(window_width, window_height, bpp, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWSURFACE);  // setting up Gl  GL_Setup(window_width, window_height);  if (windowreshape == 2)     windowreshape=0;}<small>(reformatted for clarity)</small>
Renran
Renran
Thank You guys,

Because there were rumours about loading bmp textures with "AUX_RGBImageRec"
and memory leaking I tested all the bmp loading procedures(100).
No problems there.
Then I found another subroutine for loading tga files and between the 200
files to load there were 2 tgafiles who were corrupting my program.
It took some time I must say.
So I found the problem.
Anyway thanks for your help pointing me to the right things to look for.

RenRan

Strange that the tga loading routine gives no error!
Wan
Wan
Perhaps it wouldn't have helped in your case, but I usually include _CrtSetDbgFlag in my code to quickly spot memory leaks.
Renran
Renran
Thank You Wan.
I will try it out!

RenRan
gumpy
gumpy
Quote:
Original post by Renran
...
SDL_SetVideoMode(window_width, window_height, bpp, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWSURFACE | SDL_FULLSCREEN);
...

SDL_HWSURFACE doesn't apply to OpenGL and you're supposed to use SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) to (attempt to) enable double buffering.
See here.
This space for rent.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.