   What's wrong with this code
    int videoFlags;    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )    {   return false;   }    /* the flags to pass to SDL_SetVideoMode */    videoFlags  = SDL_OPENGL;/* Enable OpenGL in SDL */   if(isFullScreen)videoFlags |= SDL_FULLSCREEN;    //If there was an error in setting up the screen    if( SDL_SetVideoMode( screenWidth, screenHeight, screenBpp,  videoFlags) == NULL )    {   return false;   }The compiler always reports the following with the location at line SDL_SetVideoMode().Unhandled exception at 0x091238e5 in myProject.exe: 0xC0000005: Access violation writing location 0x20223000.Any advice is highly appreciated.   
Quote:Original post by mylifemysoulThe compiler always reports the following with the location at line SDL_SetVideoMode().Unhandled exception at 0x091238e5 in myProject.exe: 0xC0000005: Access violation writing location 0x20223000.The compiler? Are you sure? That looks more like a run-time error to me...Have you stepped through the code in a debugger?   ;  I'd say what's wrong with it is you've posted it here expecting people to debug it for you ;).From what I can see, nothing is wrong with it. What are you passing in to screenWidth, screenHeight and screenBpp?   ;Quote:Original post by Jonny_SI'd say what's wrong with it is you've posted it here expecting people to debug it for you ;).From what I can see, nothing is wrong with it. What are you passing in to screenWidth, screenHeight and screenBpp?No, I don't expect you to debug it. The screenWidth/Height/Bpp are correct numbers. The code to me seems to be complete correct. But, I've got that unhandled expection from time to time, which really confused me.In fact, when I search the forum, I found several similar issue. A typical one is like below.http://www.gamedev.net/community/forums/topic.asp?topic_id=298978But I still can't find what's wrong in my program.... I am so worried.   ;Quote:Original post by mylifemysoulBut I still can't find what's wrong in my program.... I am so worried.Have you stepped through the code in a debugger?;  Doesn't SDL_SetVideoMode() return a pointer to your created display? If you aren't storing it in a variable, then any attempts to access the display will be reading bad data. Probably what caused the error.   ;Quote:Original post by EctaraDoesn't SDL_SetVideoMode() return a pointer to your created display? If you aren't storing it in a variable, then any attempts to access the display will be reading bad data. Probably what caused the error.The OP said the error occurs on the line where SDL_SetVideoMode() is called, so it doesn't seem like it would have anything to do with accessing the display. (Also, it's common not to store the return value of SDL_SetVideoMode(). To me the OP's code looks to be fairly typical, and I don't see any obvious problems with it - I suspect that the real problem lies elsewhere in the code.)Quote:Original post by mylifemysoulThe screenWidth/Height/Bpp are correct numbers.Are you sure?Consider this. Since there's something wrong with your program, and since you don't know what it is, you're probably not in the best position to be stating with certainty what is and isn't correct ;-) I know that I've missed obvious things when debugging because I assumed they were correct, and I'm sure others here have as well. In short, sometimes in debugging it can be helpful to question such assumptions.Anyway, I don't know if SDL would crash in this case if presented with invalid parameters (I kind of doubt it would), but perhaps you could check these values in the debugger to make sure they're what you think they are. You might also want to check and make sure the mode being requested is supported.Also, does the crash occur in windowed mode, fullscreen mode, or both?   ;  if you're using windows, check your screen bpp in the control panel.i had a similar issue on my notebook after hooking it up to a beamer, since the video driver always changed the bpp to 16 bits in such a case.   ;Thanks for all the replies. I really appreciate it.But, the problem seems to be much worse than what I thought. I posted this thread last Friday (14th). But today (17th) when I run my program, the errors are gone...These errors seem to happen from time to time. Because I actually firstly notice the errors earlier last week. That was when I added a new class -- 'NewClass'. But when I deleted all the occurrance of the 'NewClass' in my code including the '#include NewClass.h'. The errors were still there from time to time. Then I added the 'NewClass' back in, they were also there from time to time.I couldn't find anything wrong from my code at the moment. I am still debugging it line by line. But they really drive me crazy.Is it possible that they are caused by the operation system?I am using Visual Studio 2010 with WinXP by the way.;Quote:Original post by jykQuote:Original post by EctaraDoesn't SDL_SetVideoMode() return a pointer to your created display? If you aren't storing it in a variable, then any attempts to access the display will be reading bad data. Probably what caused the error.The OP said the error occurs on the line where SDL_SetVideoMode() is called, so it doesn't seem like it would have anything to do with accessing the display. (Also, it's common not to store the return value of SDL_SetVideoMode(). To me the OP's code looks to be fairly typical, and I don't see any obvious problems with it - I suspect that the real problem lies elsewhere in the code.)Quote:Original post by mylifemysoulThe screenWidth/Height/Bpp are correct numbers.Are you sure?Consider this. Since there's something wrong with your program, and since you don't know what it is, you're probably not in the best position to be stating with certainty what is and isn't correct ;-) I know that I've missed obvious things when debugging because I assumed they were correct, and I'm sure others here have as well. In short, sometimes in debugging it can be helpful to question such assumptions.Anyway, I don't know if SDL would crash in this case if presented with invalid parameters (I kind of doubt it would), but perhaps you could check these values in the debugger to make sure they're what you think they are. You might also want to check and make sure the mode being requested is supported.Also, does the crash occur in windowed mode, fullscreen mode, or both?Thanks for the suggestion. Now the errors are gone. But I think it would come back again later. When the errors were there, I only tested the windowed mode. I will adope your suggestions when they come back again.   