Andrettin / Wyrmsun

Strategy game based on history, mythology and fiction
http://andrettin.github.io/
GNU General Public License v2.0
301 stars 47 forks source link

Crash at the end of the game #28

Closed KroArtem closed 8 years ago

KroArtem commented 8 years ago

Wyrmsun & Wyrmgus the latest. I've played custom game, defeated 3 opponents, came to main menu and pressed Exit. This is what happened:

game ends
[Thread 0x7fffeaa35700 (LWP 5974) exited]

Program received signal SIGSEGV, Segmentation fault.
__GI___libc_free (mem=0x76007200370038) at malloc.c:2933
2933    malloc.c: Нет такого файла или каталога.
(gdb) bt
#0  __GI___libc_free (mem=0x76007200370038) at malloc.c:2933
#1  0x00000000007a5663 in CUnitType::~CUnitType (this=0x5e1d150, 
    __in_chrg=<optimized out>)
    at /home/kroartem/SVN/Wyrmgus/src/unit/unittype.cpp:864
#2  0x00000000007a8bd2 in CleanUnitTypes ()
    at /home/kroartem/SVN/Wyrmgus/src/unit/unittype.cpp:1882
#3  0x00000000006040c3 in CleanModules ()
    at /home/kroartem/SVN/Wyrmgus/src/game/loadgame.cpp:100
#4  0x0000000000710e1b in Exit (err=0)
    at /home/kroartem/SVN/Wyrmgus/src/stratagus/stratagus.cpp:417
#5  0x000000000071164f in stratagusMain (argc=1, argv=0x7fffffffdf38)
    at /home/kroartem/SVN/Wyrmgus/src/stratagus/stratagus.cpp:789
#6  0x00000000006da87d in main (argc=1, argv=0x7fffffffdf38)
    at /home/kroartem/SVN/Wyrmgus/src/stratagus/main.cpp:37
Andrettin commented 8 years ago

Unfortunately I could neither replicate the issue nor identify what is wrong. It seems like something is wrong with the memory allocation of OverlayAnimation objects, but I'm not sure what; they aren't defined much differently from the VariationInfo objects.

I did, however, make some improvements to the OverlayAnimation code here: https://github.com/Andrettin/Wyrmgus/commit/feefe55463507ec0f9ebbe774ab2d6065056096d

Hopefully that solves the issue.

KroArtem commented 8 years ago

I don't know what caused the issue but thought something could be wrong with destructors: like, deleting already deleted data or something similar. If it is something in memory allocation, it'll show up during the game, not when you're exiting it. However, will try to re-check, but this will require more time.

KroArtem commented 8 years ago

No, the problem still exists with absolutely the same stacktrace. Moreover, it happens even if I just start Wyrmsun and exit it.

Andrettin commented 8 years ago

Hmm :(

Yes, it sounds like something is wrong with the destructor, but I don't see what. The deletion of the data is set up in the same way as the VariationInfo, and that one is not causing such an error.

KroArtem commented 8 years ago

Ok, it always refers to the same piece.

for (int i = 0; i < AnimationFrameMax; ++i) {
        if (this->ShieldAnimation[i]) {
            delete this->ShieldAnimation[i];
        }
    }

With this unit: DefineUnitType("unit-revealer", { Name = "Dummy unit",

And it doesn't seem to have any ShieldAnimation.

Andrettin commented 8 years ago

Thanks! "unit-revealer" is the first unit to be defined, so it makes sense that the crash would happen on it. As you mentioned though, it doesn't have any ShieldAnimation (nor does it have a parent unit type either), so I wonder how it is passing the "if (this->ShieldAnimation[i])" conditional.

Andrettin commented 8 years ago

I wonder if it has something to do with the OverlayAnimation class having only ints in it as variables?

Andrettin commented 8 years ago

Another idea - perhaps your compiler is ignoring that IF statement?

Andrettin commented 8 years ago

I found the reason for this issue, it was due to an error in initializing the variable. Fixed here: https://github.com/Andrettin/Wyrmgus/commit/4f222a018978c0b5a9f2d8345e882a9fdea90e83