MantisBT - VCMI
View Issue Details
0003160VCMIMechanics - Battlespublic2020-12-13 07:582024-01-30 19:17
0003160: Crash on some battle actions
The bug is well reproducible, but it takes some time of gameplay to get to it. The bug is: If an experienced stack, that casts some magic before attack, attacks a weak stack, then it may be that this magic casting already kills the stack. Now if then after that magic the original attack takes place, this affects an already dead (aka no more existent) stack. This immediately crashes the game with a memory access violation.
This mostly happens with Gogs and Liches. F.ex. Gogs cast fireball before attacking. If that fireball already kills the stack, then the following original attack crashes the game.
I assume that a stack, that gets killed, is removed (the object is deleted). So the pointer to the object is now invalid. The subsequent attack uses this invalid pointer and so crashes the game.
Suggestion: When killing a stack, after deleting the object, set the pointer to NULL. And then before any action, check for NULL pointer, and if so, just do nothing.
It takes some time of gameplay to reproduce this. You need an experienced stack of Gogs or Liches. And preferably a big stack. Now take that big experienced stack and attack a weak stack (f.ex. a single level 1 creature). You see the pre-attack magic taking place and killing the stack. Then the subsequent attack crashes the game.
It is not possible to reproduce this bug with a fresh new map on day 1. To reproduce it you need a sufficiently experienced stack. You get easier to a sufficiently experienced stack on big maps.
This bug seems to not only happen in real battles with at least 1 human player. It seems it also happens in pure AI battles. At least the crash messages and the logs point to this.
No tags attached.
related to 0002444closed SXX Game crashes when AI wants to fight Mogogs during its turn. 
Issue History
2020-12-13 07:58SiegfriedNew Issue
2020-12-13 08:46misioklesNote Added: 0007961
2022-03-25 06:49PovelitelNote Added: 0008203
2022-03-25 06:49PovelitelAssigned To => Povelitel
2022-03-25 06:49PovelitelStatusnew => feedback
2022-03-28 18:28PovelitelRelationship addedrelated to 0002444
2022-11-26 14:43PovelitelAssigned ToPovelitel =>
2024-01-30 19:17IvanStatusfeedback => closed

2020-12-13 08:46   
I can confirm that sometimes it happens.
2022-03-25 06:49   
I tried to reproduce it but couldn't. I suspect the whole thing is in the second shot of the magog, when the creature has already died, and the second shot works.
Or the problem is in the combination of some secondary skills or artifacts.
Do you still repeat this? No matter how hard I tried, I couldn't reproduce it.