Sign in to follow this  
chosenkill6

SDL_SetVideoMode randomly stops working?

Recommended Posts

I have been working on a game of pong and i am using VC++ 2010 as my compiler and the problem is that SDL_SetVideoMode randomly stops working?
I added a small line of code, went to compile and it took me to the line with SDL_SetVideoMode on it and i got this message:



First-chance exception at 0x1002bb63 in Pong.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x1002bb63 in Pong.exe: 0xC0000005: Access violation reading location 0x00000000.

I thought it had something to do with my code so i commented that out and now im still getting the error?
I made a copy of the project and have been messing around with the linker input so if someone coulde give me the order that SDL links in that would be great. i am using sdl, sdl image

thanks

Share this post


Link to post
Share on other sites
[quote name='Wooh' timestamp='1318897195' post='4873692']
[quote]Access violation reading location 0x00000000[/quote]looks like you trying to read from a null pointer.
[/quote]
That's what I thought too, but my program was compiling fine just the way it is. I didn't even edit the code and it just stopped working
Another thing I noticed is that if I put return false right after it will work but then throw me the same or similar error somewhere else in my code

Share this post


Link to post
Share on other sites
I tried to compile using breakpoints to see where my code messes up and it executes uptil SDL_SetVideoMode fine, and then after throws me an error. Could it be because my screen variable is global? i have done this many times before but this time that is all i can think of...


PLease help i havent been able to work on my project since...

Share this post


Link to post
Share on other sites
I fixed it!
I'm kinda glad i was able to fix it by myself so that in the future i am able to debug better. I commented out large chunks of my code and compiled. Saw if it worked and then made the comments smaller, repeated this till it would give me an error :P

The problem was that one of my images wasn't loading properly, i dont know how this can cause problems with SDL_SetVideoMode but it did. I have a log that i load and that log should tell me if any images did not load but that log was empty, haha it only works when the program runs fine so if someone can give me a link on a tut about properly using logs :P

Anyways thanks guys

Share this post


Link to post
Share on other sites
[quote]
I fixed it!
I'm kinda glad i was able to fix it by myself so that in the future i am able to debug better. I commented out large chunks of my code and compiled. Saw if it worked and then made the comments smaller, repeated this till it would give me an error
[/quote]
Great stuff. This kind of divide and conquer approach can be very useful. It can be time consuming though. It can also negatively affect your code (unless you create a copy, or use version control. I recommend the latter, but the former will work too).

In this case though, once you have some experience using your debugger you will likely find that a far more efficient way to investigate these sorts of errors.

[quote]
I have a log that i load and that log should tell me if any images did not load but that log was empty, haha it only works when the program runs fine so if someone can give me a link on a tut about properly using logs
[/quote]
How often do you flush your log? The basic I/O optimisations are caching and buffering. If you aren't explicitly flushing your logs, the data might be sitting in an application buffers, OS buffers, or both. When your process crashes, the OS will flush its buffers but it knows nothing about the application buffers.

How are you logging? If you're using the C file streams, you need to insert fflush() calls. If the C++ streams, you can insert std::flush or std::endl* into the stream, or call the flush() member function of the stream object.

* [size="1"]Note that this is one reason you should not use std::endl when you don't need flushing behaviour, because it is both a newline and a flush it can negatively impact performance when you need to write a large amount of data to a file.[/size]

Share this post


Link to post
Share on other sites
Yeah I did make a copy of the entire source and project files and backed them up to Dropbox before I started messing around trying to fix the problem

I'm using c file stream so I will probably add fflush. Is there any reason not to add fflush or is it okay to use it after everytime I output something to my log?

Share this post


Link to post
Share on other sites
If you want the log to be available in the case of a sudden crash, you'll need to flush it after each logical entry. One option is to wrap your logging in a custom function, and flush as part of that. Another might be [url="http://stackoverflow.com/questions/214271/c-equivalent-of-autoflush"]this[/url].

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1319030015' post='4874314']
If you want the log to be available in the case of a sudden crash, you'll need to flush it after each logical entry. One option is to wrap your logging in a custom function, and flush as part of that. Another might be [url="http://stackoverflow.com/questions/214271/c-equivalent-of-autoflush"]this[/url].
[/quote]

I think I'm just going to insert an fflush after each output to the log, it will be much more easier to add to my current code

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