Fixed Segfault when overriding talent.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-08-01 10:27:46 +02:00
parent fa5184ad77
commit 670abd7229
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 12 additions and 2 deletions

View File

@ -171,10 +171,12 @@ void Battling::Creature::Heal(uint32_t amount, bool canRevive) {
void Battling::Creature::OverrideActiveTalent(const ArbUt::StringView& talent) {
_hasOverridenTalent = true;
if (_activeTalent != nullptr) {
_activeTalent->OnRemove();
_overridenTalentName = talent;
_activeTalent.reset(this->_library->LoadScript(ScriptCategory::Talent, talent));
}
_overridenTalentName = talent;
}
const std::unordered_set<uint8_t>& Battling::Creature::GetTypes() const noexcept { return _types; }

View File

@ -46,4 +46,12 @@ TEST_CASE("Increase creature stat boost", "[Library]") {
delete creature;
}
TEST_CASE("Override Creature talent", "[Library]") {
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
creature->OverrideActiveTalent("foobar");
REQUIRE(creature->GetActiveTalent() == "foobar");
delete creature;
}
#endif