Possible causes of a segmentation fault?

Started by
4 comments, last by snisarenko 18 years, 4 months ago
Ok, I've got a segmentation fault error on a PS2. I'm not quite sure what the problem is. The PS2 Linux kit is infamous for its lack of debugging tools so all I can do is use printfs to find the problem. It looks like the error is tied to a "new"ed (dynamically allocated) array of a class which contains a matrix class which includes a float[16] variable. I'm really shooting in the dark at the moment. Any ideas/tips?
Advertisement
Stuff like that:
float omg=*(float*)0; // Reading/writing from/to a memory location you shouldn't.
will cause a segmentation fault.
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
Ok thanks, I'll look out for something like that. :)
I seg fault all the time - it's my boss's fault. I'll be sitting there coding, then he'll ping me on IM w/ "Do you are it's working?"

I just blink a few times, then have to reboot.
-- Succinct(Don't listen to me)
Does the linux dev kit not have gdb? gdb is excellent and finding seg faults.
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd
It might be helpful to catch the segfault signal with your own handler and not the default one that just terminates the program.

#include <signal.h>void handler(int signo){  //you handling code goes here}int main(){   struct sigaction segfaultaction;      /*initialize the action*/    segfaultaction.sa_handler = handler;    if(sigemptyset(&segfaultaction.sa_mask)<0)    {        printf("Error filling a sigset\n");        return -1;    }    tickaction.sa_flags=0;    if(sigaction(SIGSEGV,&segfaultaction,NULL)<0)    {        printf("Error setting action\n");        return -1;    }}


[Edited by - snisarenko on December 3, 2005 7:02:23 PM]

This topic is closed to new replies.

Advertisement