Why is this segfaulting???

Started by
32 comments, last by jimi_hendrix 15 years, 4 months ago
i am using SDL this code compiles but segfaults on startup I have been trying all morning but cannot find the segfault...i have noticed that it will run if you comment line 109... other segfaults...when the stars hit the bottom of the screen and if you hit spacbar (because i have not finished that part...) but the screen one bottles me too this is my first big(as in a lot of lines) program in C++ pastebin for code http://pastebin.com/m32c4319c
Advertisement
Well, I'm not sure. Where does the debugger tell you the segfault is, and why does it tell you the segfault is happening?
Okay, that's pretty much what I said you shouldn't do.

Have you checked for dereferencing uninitialized or null pointers?
Have you set break points, what does your debugger say?
@Snef

i am using g++ in linux...so it just says Segmentation Fault...i put in a cout statement in there to see if i even get that far and i dont

i think it has to do with the missile class or its instatiation in the player class

@Wan

what else do you want to know?
Quote:Original post by jimi_hendrix
i am using g++ in linux...so it just says Segmentation Fault...i put in a cout statement in there to see if i even get that far and i dont
Right. Because you're not running it in the debugger. Run it in the debugger. It's for debugging.

Just to make things a little clearer: A programmer trying to find a segfault somewhere in a large block of code is like a carpenter trying really hard to push a nail into a piece of wood with his hands. And when he can't, he posts "hey, can anyone push in this nail with their hands? I can't get it in!" on a message board. We don't push nails in with our hands. We use hammers. Learn to use your debugger.
More precisely, read Debugging with gdb, which is the debugger that you will want to use with g++. Or, just use an IDE that takes care of the debugger handling, such as Eclipse or Code::Blocks, then it all comes down to pressing one button.
ok

so now after removing multiple segfaults i have a segfault in the SDL_DisplayFormat() in loadImage()...this did not segfault before...why would it segfault now?
what would be the appropriate tool to answer that question.
a debugger? assert()? prayers?
Quote:Original post by jimi_hendrix
a debugger? assert()?

That's a rodger.

This topic is closed to new replies.

Advertisement