![]() |
|
Tackeling segmentation fault (nasty bug is ruining my game) |
Ariesnl
Member #2,902
November 2002
![]() |
See attachment For some strange reason these kind of errors are always ruining my projects. I almost never find the solution. Someone advised me to remove all external declarations.. even that did not work .. Is there any smart way to fix this ?? I have Dev-C++ and code::Blocks to work with BTW tips on improving my code are also welcome I tried to use GDB.. can anyone make sense out of this ? gdb: kernel event for pid=860 tid=1940 code=EXCEPTION_DEBUG_EVENT) Program received signal SIGSEGV, Segmentation fault. Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
ImLeftFooted
Member #3,935
October 2003
![]() |
Recompile your entire project with the options: -ggdb3 -g3 On first glance I would guess you're passing a bad char* to cout. |
Ariesnl
Member #2,902
November 2002
![]() |
I'm affraid I got the same information: gdb: kernel event for pid=3244 tid=3240 code=EXCEPTION_DEBUG_EVENT) Program received signal SIGSEGV, Segmentation fault. this is my compile log from Dev-C++
Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
ImLeftFooted
Member #3,935
October 2003
![]() |
You have to add it to the linker command as well. |
Kitty Cat
Member #2,815
October 2002
![]() |
I don't see -W -Wall in that command line, mister.. -- |
Ariesnl
Member #2,902
November 2002
![]() |
ok now I get this : gdb: kernel event for pid=3588 tid=3472 code=EXCEPTION_DEBUG_EVENT) Program received signal SIGSEGV, Segmentation fault. -w -wall ?? explain please Edit: -Wall -w hmm I guess I only need -wall of those 2 ? right ? anyway I tried .. no warnings ... Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
ImLeftFooted
Member #3,935
October 2003
![]() |
Did you do a complete recompile? |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: hmm I guess I only need -wall of those 2 ? right ? -w != -W -W -Wall is different from -w -wall -- |
Ariesnl
Member #2,902
November 2002
![]() |
@ Dustin Dettmer: I even cleaned it and recompiled, after that I manually removed all *.o files and recompiled all gave the same results.. should I try compiling manually ? (command line compiler) .. I've never done that though... @Kitty Cat: Hmm you're right Now I get loads of warnings .. and a lot are coming from Open Layer.. How bad is Not having a virtual destructor when having virtual functions in a class ? hmm this is fladimir's code : inline Vec2D &GetVertex( unsigned int index ) { I always do this : if ( (index < 0) || (index >= vertices.size())) Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
ImLeftFooted
Member #3,935
October 2003
![]() |
Quote: I even cleaned it and recompiled Paste in the compiler log again. Quote: How bad is Not having a virtual destructor when having virtual functions in a class ? Its bad if you ever call delete on a base class pointer that actually refers to a child instance. class Foo { ~Foo(){} }; class Bar : Foo { ~Bar(){} }; .. Foo *foo = new Bar; delete foo; // BAD!!
class Foo { virtual ~Foo(){} }; class Bar : Foo { virtual ~Bar(){} }; .. Foo *foo = new Bar; delete foo; // Good!
|
Ariesnl
Member #2,902
November 2002
![]() |
I have an ancestor sprite from wich all the other things are derived..
But my "units" don't claim any memory by theirselves, so what should be in the destructor ? or just an empty virtual destructor ? Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
Thomas Harte
Member #33
April 2000
![]() |
I'm sorry, I don't really know the Dev-C++ or code::Blocks environments, but my recommendation is that you equip yourself with a memory debugger like Dmalloc or Electric Fence (I use Guard Malloc, but I don't think it's available for Windows). Normally a debugger will tell you where your program crashed, which means you can work out what it was doing at the time. But if you have some wacky memory usage error, then the incorrect piece of code can cause the program to crash at some other, correct, piece of code. Which makes the error very hard to find. What memory debuggers like Dmalloc and Electric Fence do is replace malloc/etc with alternative versions that make your code run much slower but make it crash at the point of bad memory usage. The idea is that you link them into your debug build, fix all the errors, then ship your product without them. [My site] [Tetrominoes] |
Kitty Cat
Member #2,815
October 2002
![]() |
I still don't see -W and -Wall in your compile command line. -- |
Ariesnl
Member #2,902
November 2002
![]() |
I did compile with -W -WALL .. fixed the warnings in MY code after that recompiled without.. else you would have a very long list here ...and Dustin Dettmer wanted to see what I did with -ggdb3 -g3. But I can recompie with -W -Wall ant put it up here, just don't say I didn't warn you That memory debugger is a good idea, does it also work with new and delete ? ( I only see malloc there) Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
ImLeftFooted
Member #3,935
October 2003
![]() |
Quote: But my "units" don't claim any memory by theirselves, so what should be in the destructor ? or just an empty virtual destructor ? Empty is fine. They just must be there and must be virtual for both base class and all inheriting classes. This sort of problem could potentially cause your program to freak out and segfault like it is. |
Ariesnl
Member #2,902
November 2002
![]() |
EDIT : I put in a virtual destructor everywhere but if I enable the "score counting" here is the new code http://www.allegro.cc/files/attachment/591955 Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
|