Sign in to follow this  
Renran

Strange C++ issue ?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;
}

(reformatted for clarity)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this