SDL Creation and sudden destruction

Started by
5 comments, last by Wooh 12 years, 9 months ago
Hello,


I am having problems with my RenderDevice function (Constructor within the RenderDevice class) in an engine i am developing at the moment. It isnt a final wanted function, but a test for SDL.


My problem is that a SDL window is created, but somehow exits the while loop (from what it appears) but that isnt possible as the variable checked for program end isnt even changed. I took out SDL_quit and it had still closed. From what i was instructed, is that my use of MSVC 2010 ultimate May be interfering with SDL itself. (it being a wrong version or recompilation of the libraries is needed) On the site i took into consideration of reading, lazyfoo, it had Told to go through the steps to use the libraries. I am using the instructed libraries for the project im working on in the compiler im on. So this should not be a problem and have a feeling that the problem lies within the code itself. I however have checked multiple times to see what it could be, and it was no use in my eyes. So i have come here to see if anyone else has encountered this problem or have a possible hint to fixing mine.



RenderDevice(int x_size, int y_size, int Bits_Per_Pixel, char* windowTitle, char* taskbarTitle, void (*execute_per_frame)() ) {

vTimerObject timerobj; //Sets up a timer object to continuously get last time between function calls to calculate fps
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* Window = NULL;
SDL_Event WindowEvent;

Window = SDL_SetVideoMode( x_size, y_size, Bits_Per_Pixel, SDL_SWSURFACE);
if (Window == NULL) { MessageBox(NULL, "Window Creation Failed", "Engine Initialization Failure", MB_ICONEXCLAMATION | MB_OK); }
SDL_WM_SetCaption(windowTitle, taskbarTitle);

while(this->end_rendering == false) { //While device end_rendering not set

if (SDL_PollEvent(&WindowEvent) != 0) {
if (WindowEvent.type == SDL_QUIT) { this->window_close_requested = true; }
}

if (SDL_Flip(Window) != 0) { MessageBox(NULL, "Window Update Failure", "Engine Runtime Error", MB_ICONEXCLAMATION | MB_OK); }
//GetLastTick();
execute_per_frame(); //Programmers loop, game function to call every frame
this->fps = (1000/timerobj.GetLastTick()); //get fps


}
SDL_Quit();

//DEALLOCATION and ENGINE END functions go here. once the person calls
}





Is there a possibility that its got something to do with my code?
Advertisement
It looks like you never initialize end_rendering in the constructor. That means end_rendering could be true and therefore never enter the loop. Try initialize end_rendering to false and see if that makes a difference.
I have already tried it, From what ive read any bool variable defaults to false. Either way ive tried initializing it, but it still hadnt worked.
From what ive read any bool variable defaults to false.
That is true for some languages but not for C or C++.
It hasnt worked anyway. :/
A more straightforward and to the point description of the problem is



The SDL window is created and is then suddenly destroyed but the program stays in memory


The executable calling this function from its dll has a system("PAUSE") before and after the function call.

Press any key to continue. . .
*
Window creation,
window destruction
*
Press any key to continue. . .

Is all that is seen
I think it we need more code to be able to help.

This topic is closed to new replies.

Advertisement