Program running in CodeBlocks but not in VC++ 2010?

Started by
7 comments, last by chosenkill6 12 years, 6 months ago
I am trying to make a game using SDL but when i try to run it in VC++ 2010 it gives me error: "Unhandled exception at 0x1002bb63 in simple.exe: 0xC0000005: Access violation reading location 0x00000000."
also it takes me to the line that i am setting my screen in which is like this: SDL_SetVideoMode(1024,768,32,SDL_SWSURFACE);
The same program runs fine in codeblocks... If i pass SDL_OPENGL instead of SDL_SWSURFACE it runs but i cant use that since i dont know OpenGL...
I can post entire source code and the VC++ project files if necessarily.

Thanks
Advertisement
That means you're trying to use a null pointer. Check your pointers to make sure they're not null. If they are, use SDL_GetError() to find out what happened.
i dont think that i am using a null pointer because i used sdlgeterror and it doesnt reveal anything, in fact the log is blank, which means that my init funstion did not run succesfully
Here is the code that im using



SDL_Surface *screen = NULL;

screen = SDL_SetVideoMode(1024,768,0,SDL_SWSURFACE); //Set screen
if(screen == NULL)
{
fprintf(fp,"Unable to load window: %s\n", SDL_GetError());
return false;
}



Can this possibly be a VC++ problem because this runs fine in codeblocks
Did you ever call SDL_Init()?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


Did you ever call SDL_Init()?


yeah, i called SDL_Init(SDL_INIT_EVERYTHING)
I know that my code is fine because it runs in codeblocks but i copy and paste to VC++ and it compiles but gives me that wierd error and sends me to the line i am setting the video mode...
Lets back up a bit. What SDL are you using? Are you using the source code, runtime libraries, or development libraries? I just looked at SDL's download page and they have different development libraries for Mingw32 (used with Code::Blocks) and Visual Studio.

If your SDL_Init() function didn't run successfully, it will return -1 You should check that and then run SDL_GetError() to see why.

A quote from an SDL wiki
You can get extended error message by calling SDL_GetError. Typical cause of this error is using a particular display without having according subsystem support, such as missing mouse driver when using with framebuffer device. In this case you can either compile SDL without mouse device, or set "SDL_NOMOUSE=1" environment variable before running your application.[/quote]
Maybe you should try to initialize the subsystems seperately, to see which one it doesn't like.

My money is on the wrong development libraries, though.
I got it working!
I looked in the linker input section and there was some .lib file, gles2.lib(I don't think tht was the name but it was similar) and I took it out and my program worked. Now I'm wondering how tht lib got there...
Just so you don't get burned by this later, the fact your code ran fine on one platform/compiler/whatever and not another doesn't mean it doesn't have a bug. When you get into bad pointers, the behavior varies from one platform or compiler to another, or even between release and debug mode. Often for example, once compiler will zero out deallocated objects, which result in a null pointer exception, while another may just mark them as unallocated, but the values in memory still appear to be correct.

This can lead to some extremely hard to understand bugs.

Just so you don't get burned by this later, the fact your code ran fine on one platform/compiler/whatever and not another doesn't mean it doesn't have a bug. When you get into bad pointers, the behavior varies from one platform or compiler to another, or even between release and debug mode. Often for example, once compiler will zero out deallocated objects, which result in a null pointer exception, while another may just mark them as unallocated, but the values in memory still appear to be correct.

This can lead to some extremely hard to understand bugs.


Yeah, that is the reason i usually set all my pointers to NULL when initializing them because it is much easier to check if they hold the intended value later on in the program

This topic is closed to new replies.

Advertisement