Sign in to follow this  
chosenkill6

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

Recommended Posts

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

Share this post


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


[code]
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;
}[/code]


Can this possibly be a VC++ problem because this runs fine in codeblocks

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1318467098' post='4872059']
Did you ever call SDL_Init()?
[/quote]

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...

Share this post


Link to post
Share on other sites
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 [b]-1[/b] You should check that and then run SDL_GetError() to see why.

A quote from an SDL wiki
[quote]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.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
[quote name='Serapth' timestamp='1318518014' post='4872209']
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.
[/quote]

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

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