Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Tackeling segmentation fault (nasty bug is ruining my game)

This thread is locked; no one can reply to it. rss feed Print
Tackeling segmentation fault (nasty bug is ruining my game)
Ariesnl
Member #2,902
November 2002
avatar

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 ;D

I tried to use GDB.. can anyone make sense out of this ?

gdb: kernel event for pid=860 tid=1940 code=EXCEPTION_DEBUG_EVENT)
gdb: Target exception EXCEPTION_ACCESS_VIOLATION at 0x6965ae9c

Program received signal SIGSEGV, Segmentation fault.
0x6965ae9c in nvoglnt!DllMain () from C:\WINDOWS\system32\nvoglnt.dll
(gdb) backtrace
#0 0x6965ae9c in nvoglnt!DllMain () from C:\WINDOWS\system32\nvoglnt.dll
#1 0x03824fd4 in ?? ()
#2 0x0381a518 in ?? ()
#3 0x0022fca8 in ?? ()
#4 0x00001401 in ?? ()
#5 0x004479b0 in gk_render_line_gl_utf8 ()
at C:/Program Files/CodeBlocks/bin/../lib/gcc/mingw32/3.4.4/../../../../incl
ude/c++/3.4.4/iostream:77
Previous frame inner to this frame (corrupt stack?)
(gdb)

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

ImLeftFooted
Member #3,935
October 2003
avatar

Recompile your entire project with the options: -ggdb3 -g3
Then run again, pasting the results.

On first glance I would guess you're passing a bad char* to cout.

Ariesnl
Member #2,902
November 2002
avatar

I'm affraid I got the same information:

gdb: kernel event for pid=3244 tid=3240 code=EXCEPTION_DEBUG_EVENT)
gdb: Target exception EXCEPTION_ACCESS_VIOLATION at 0x6965ae9c

Program received signal SIGSEGV, Segmentation fault.
0x6965ae9c in nvoglnt!DllMain () from C:\WINDOWS\system32\nvoglnt.dll
(gdb) backtrace
#0 0x6965ae9c in nvoglnt!DllMain () from C:\WINDOWS\system32\nvoglnt.dll
#1 0x03824fcc in ?? ()
#2 0x0381a518 in ?? ()
#3 0x0022fca8 in ?? ()
#4 0x00001401 in ?? ()
#5 0x004479b0 in gk_render_line_gl_utf8 ()
at C:/Program Files/CodeBlocks/bin/../lib/gcc/mingw32/3.4.4/../../../../incl
ude/c++/3.4.4/iostream:77
Previous frame inner to this frame (corrupt stack?)
(gdb)

this is my compile log from Dev-C++

1Compiler: Default compiler
2Building Makefile: "D:\Develop\ViperFighter\Makefile.win"
3Executing make clean
4rm -f bsgBattlestar.o bsgBullet.o bsgExplosion.o bsgLeftBay.o bsgPlayer.o bsgRaider.o bsgShip.o bsgSmoke.o bsgTurret.o bsgViper.o Engine.o Main.o particle.o spartan.o ViperFighter.exe
5 
6g++.exe -c bsgBattlestar.cpp -o bsgBattlestar.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
7 
8g++.exe -c bsgBullet.cpp -o bsgBullet.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
9 
10g++.exe -c bsgExplosion.cpp -o bsgExplosion.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
11 
12g++.exe -c bsgLeftBay.cpp -o bsgLeftBay.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
13 
14g++.exe -c bsgPlayer.cpp -o bsgPlayer.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
15 
16g++.exe -c bsgRaider.cpp -o bsgRaider.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
17 
18g++.exe -c bsgShip.cpp -o bsgShip.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
19 
20g++.exe -c bsgSmoke.cpp -o bsgSmoke.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
21 
22g++.exe -c bsgTurret.cpp -o bsgTurret.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
23 
24g++.exe -c bsgViper.cpp -o bsgViper.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
25 
26g++.exe -c Engine.cpp -o Engine.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
27 
28g++.exe -c Main.cpp -o Main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
29 
30g++.exe -c particle.cpp -o particle.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
31 
32g++.exe -c spartan.cpp -o spartan.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
33 
34g++.exe bsgBattlestar.o bsgBullet.o bsgExplosion.o bsgLeftBay.o bsgPlayer.o bsgRaider.o bsgShip.o bsgSmoke.o bsgTurret.o bsgViper.o Engine.o Main.o particle.o spartan.o -o "ViperFighter.exe" -L"C:/Dev-Cpp/lib" -L"C:/OpenLayer2.0/Libs" -mwindows C:/OpenLayer2.0/Libs/libopenlayer.a C:/OpenLayer2.0/Libs/libglyph.a C:/OpenLayer2.0/Libs/libfreetype.a C:/OpenLayer2.0/Libs/libloadpng.a C:/OpenLayer2.0/Libs/libpng.a C:/OpenLayer2.0/Libs/libz.a C:/OpenLayer2.0/Libs/libagl.a C:/OpenLayer2.0/Libs/liballeg.a C:/Dev-Cpp/lib/libuser32.a C:/Dev-Cpp/lib/libgdi32.a C:/Dev-Cpp/lib/libglu32.a C:/Dev-Cpp/lib/libopengl32.a C:/Dev-Cpp/lib/libfmod.a
35 
36Execution terminated
37Compilation successful

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

ImLeftFooted
Member #3,935
October 2003
avatar

You have to add it to the linker command as well.

Kitty Cat
Member #2,815
October 2002
avatar

I don't see -W -Wall in that command line, mister.. :-X

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Ariesnl
Member #2,902
November 2002
avatar

ok now I get this :

gdb: kernel event for pid=3588 tid=3472 code=EXCEPTION_DEBUG_EVENT)
gdb: Target exception EXCEPTION_ACCESS_VIOLATION at 0x6965ae9c

Program received signal SIGSEGV, Segmentation fault.
0x6965ae9c in nvoglnt!DllMain () from C:\WINDOWS\system32\nvoglnt.dll
(gdb) backtrace
#0 0x6965ae9c in nvoglnt!DllMain () from C:\WINDOWS\system32\nvoglnt.dll
#1 0x04d68fd4 in ?? ()
#2 0x03dfa4e0 in ?? ()
#3 0x0022fc98 in ?? () at locale_facets.tcc:2492
#4 0x00001401 in ?? () at locale_facets.tcc:2492
#5 0x00448f80 in gk_render_line_gl_utf8 () at iostream:77
Previous frame inner to this frame (corrupt stack?)
(gdb)

-w -wall ?? explain please

Edit:

-Wall
Turns on all optional warnings which are desirable for normal code. At present this is -Wcomment, -Wtrigraphs, -Wmultichar and a warning about integer promotion causing a change of sign in #if expressions. Note that many of the preprocessor's warnings are on by default and have no options to control them.

-w
Suppress all warnings, including those which GNU CPP issues by default.

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)
Current project: [Star Trek Project ] Join if you want ;-)

ImLeftFooted
Member #3,935
October 2003
avatar

Did you do a complete recompile?

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

hmm I guess I only need -wall of those 2 ? right ?

-w != -W

-W -Wall is different from -w -wall

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Ariesnl
Member #2,902
November 2002
avatar

@ 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 ?
the class does not claim memory by itself ... no new or malloc, except for bullets etc. but they are passed to the engine and destroyed there

hmm this is fladimir's code :

inline Vec2D &GetVertex( unsigned int index ) {
static Vec2D dummyValue;

if( index < 0 || index >= vertices.size()) {
OlError( "Invalid vertex index: " + ToString( index )
+ " ( Number of vertices: " + ToString( vertices.size()) + " )" );
return dummyValue;
}

return vertices[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)
Current project: [Star Trek Project ] Join if you want ;-)

ImLeftFooted
Member #3,935
October 2003
avatar

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
avatar

1Compiler: Default compiler
2Building Makefile: "D:\Develop\ViperFighter\Makefile.win"
3Executing make clean
4rm -f bsgBattlestar.o bsgBullet.o bsgExplosion.o bsgLeftBay.o bsgPlayer.o bsgRaider.o bsgShip.o bsgSmoke.o bsgTurret.o bsgViper.o Engine.o Main.o particle.o spartan.o ViperFighter.exe
5 
6g++.exe -c bsgBattlestar.cpp -o bsgBattlestar.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
7 
8g++.exe -c bsgBullet.cpp -o bsgBullet.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
9 
10g++.exe -c bsgExplosion.cpp -o bsgExplosion.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
11 
12g++.exe -c bsgLeftBay.cpp -o bsgLeftBay.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
13 
14g++.exe -c bsgPlayer.cpp -o bsgPlayer.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
15 
16g++.exe -c bsgRaider.cpp -o bsgRaider.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
17 
18g++.exe -c bsgShip.cpp -o bsgShip.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
19 
20g++.exe -c bsgSmoke.cpp -o bsgSmoke.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
21 
22g++.exe -c bsgTurret.cpp -o bsgTurret.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
23 
24g++.exe -c bsgViper.cpp -o bsgViper.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
25 
26g++.exe -c Engine.cpp -o Engine.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
27 
28g++.exe -c Main.cpp -o Main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
29 
30g++.exe -c particle.cpp -o particle.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
31 
32g++.exe -c spartan.cpp -o spartan.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/OpenLayer2.0/Include" -ggdb3 -g3
33 
34g++.exe bsgBattlestar.o bsgBullet.o bsgExplosion.o bsgLeftBay.o bsgPlayer.o bsgRaider.o bsgShip.o bsgSmoke.o bsgTurret.o bsgViper.o Engine.o Main.o particle.o spartan.o -o "ViperFighter.exe" -L"C:/Dev-Cpp/lib" -ggdb3 -g3 -L"C:/OpenLayer2.0/Libs" -mwindows C:/OpenLayer2.0/Libs/libopenlayer.a C:/OpenLayer2.0/Libs/libglyph.a C:/OpenLayer2.0/Libs/libfreetype.a C:/OpenLayer2.0/Libs/libloadpng.a C:/OpenLayer2.0/Libs/libpng.a C:/OpenLayer2.0/Libs/libz.a C:/OpenLayer2.0/Libs/libagl.a C:/OpenLayer2.0/Libs/liballeg.a C:/Dev-Cpp/lib/libuser32.a C:/Dev-Cpp/lib/libgdi32.a C:/Dev-Cpp/lib/libglu32.a C:/Dev-Cpp/lib/libopengl32.a C:/Dev-Cpp/lib/libfmod.a
35 
36Execution terminated
37Compilation successful

I have an ancestor sprite from wich all the other things are derived..
and yes my engine just calls delete for a pointer to a sprite

1 
2void bsgEngine::kill()
3{
4 std::list<bsgSprite *>::iterator p=m_lstItems.begin();
5 while (p!=m_lstItems.end())
6 {
7 bsgSprite* pDummy=((bsgSprite *)*p);
8 if (pDummy->m_blDestroyed)
9 {
10 p=m_lstItems.erase(p);
11 if (pDummy->m_nType==ID_RAIDER)
12 {
13 m_nRaiders--; // just for demo !
14 }
15 
16 delete pDummy;
17 }
18 else
19 {
20 p++;
21 }
22 }
23}

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)
Current project: [Star Trek Project ] Join if you want ;-)

Thomas Harte
Member #33
April 2000
avatar

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.

Kitty Cat
Member #2,815
October 2002
avatar

I still don't see -W and -Wall in your compile command line. :P Sticking your head in the sand (ie. ignoring warnings) doesn't make bugs go away...

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Ariesnl
Member #2,902
November 2002
avatar

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 :P;D

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)
Current project: [Star Trek Project ] Join if you want ;-)

ImLeftFooted
Member #3,935
October 2003
avatar

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
avatar

:o no one ever told me that..
I'll fix it as soon as possible and see if it get's rid of the problem ...
Thanks ..

EDIT : I put in a virtual destructor everywhere but if I enable the "score counting"
the game still crashes..:-/
there must be something wrong but I don't see it ...

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)
Current project: [Star Trek Project ] Join if you want ;-)

Go to: