Deal with Creatures being deleted before a battle they're part of.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include "../../extern/doctest.hpp"
|
||||
#include "../../src/Battling/Models/Battle.hpp"
|
||||
#include "../../src/Battling/Models/CreateCreature.hpp"
|
||||
#include "../TestLibrary/TestLibrary.hpp"
|
||||
|
||||
@@ -54,4 +55,16 @@ TEST_CASE("Override Creature talent") {
|
||||
delete creature;
|
||||
}
|
||||
|
||||
TEST_CASE("Creature can be deleted before battle is deleted") {
|
||||
// This should not happen during normal battle executions, but can happen for certain GC solutions. We should not
|
||||
// segfault in this case, but deal with it properly.
|
||||
auto library = TestLibrary::Get();
|
||||
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
||||
auto battle = new Battle(library, {});
|
||||
auto side = battle->GetSides()[0];
|
||||
side->SetCreature(creature, 0);
|
||||
delete creature;
|
||||
delete battle;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user