Sign in to follow this  
deavik

SDL segmentation faults

Recommended Posts

deavik    570
Hi, I am writing a project with SDL and OpenGL. My program is fine, no troubles but I am getting segmentation faults in stderr.txt. This has never happenned to me before when the program was running fine, which it is. So do I have an issue? And it's also strange because all I did this morning was try something new, then I commented out the new bit again but started getting the stderr.txt file in my program folder. Has anyone had this type of thing happen to them before?

Share this post


Link to post
Share on other sites
JTippetts    12949
You've introduced an error somewhere in your code. Note that it is not likely SDL's fault; it is in your code. Look carefully at the changes you made to make sure you are not trying to write to a bad pointer somewhere. Also, it is entirely possible that the segfault has been there all along, but some quirk of compilation let it slip through, ie an overwritten pointer that didn't produce any immediate sideeffects of buffer overflow. Making and then commenting out some of your changes may have slightly changed how the final binary is assembled, enough that the segfault becomes critical, causing the exception. I've had this occur before, things getting placed in slightly different stack locations (due to inadvertent changes in the order I declare local-scope variables, and other such seemingly insignificant things) that causes a previously sneaky buffer overflow to now tromp critical memory locations instead of slipping harmlessly by.

If the program is running fine, it's likely that the segfaults are occuring during destruction just before program exit, so carefully check all destructors and all code to destroy objects to make sure something is not trying to deallocate memory twice, or something to that effect. That's really all I can tell you. Good luck.

Share this post


Link to post
Share on other sites
Rob Loach    1504
Segmentation faults usually occur when you're trying to point to a variable that doesn't exist. You might want to check your pointers and make sure they're not pointing to a null variable [smile]. Get that debugging cap on and go test out your debugging skill!

Share this post


Link to post
Share on other sites
deavik    570
Hi guys thanks for writing in! No, I am not a big pointers fan myself so I pass references as function parameters. Also, I started redoing stuff from a backup I had made yesterday (error-free) and I thought I should mention that running from the compiler gives me errors sometimes whereas just compiling and running the exe does not.

What VertexNormal said could be possible as I also fiddled around with local-scope variables as I found I had too many in some functions. But local-scope variables aren't referred to later, so as long as that function works it should be fine ...

Share this post


Link to post
Share on other sites
JTippetts    12949
Nevertheless, the error is in your code somewhere. SDL hooks in to report segfaults, but that is all. I won't say that SDL is perfect, but it _is_ mature and well-tested, and Occam's Razor, KISS, insert-other-law-here, etc... points to your code as the most likely explanation rather than the library itself. Fire up the debugger.

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