From d269ebb51a2215951336df869163145abf5dcfd2 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 28 Sep 2019 21:46:13 +0200 Subject: [PATCH] Fixed a few potential crashes. --- data/spell.cpp | 6 +++--- infos/spell_cast_info.cpp | 12 ++++++++++-- infos/spell_cast_info.h | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/data/spell.cpp b/data/spell.cpp index c726ff8..69a7c70 100644 --- a/data/spell.cpp +++ b/data/spell.cpp @@ -555,7 +555,7 @@ void Spell::set_training_required_skill_level(int value) { //// Spell System //// void Spell::sstart_casting_simple(Entity *caster, float spell_scale) { - ERR_FAIL_COND(caster == NULL); + ERR_FAIL_COND(!caster || !ObjectDB::instance_validate(caster)); Ref info = Ref(memnew(SpellCastInfo())); @@ -570,7 +570,7 @@ void Spell::sstart_casting_simple(Entity *caster, float spell_scale) { } void Spell::sinterrupt_cast_simple(Entity *caster) { - ERR_FAIL_COND(caster == NULL); + ERR_FAIL_COND(!caster || !ObjectDB::instance_validate(caster)); Ref info(memnew(SpellCastInfo())); @@ -581,7 +581,7 @@ void Spell::sinterrupt_cast_simple(Entity *caster) { } void Spell::sstart_casting_triggered_simple(Entity *caster) { - ERR_FAIL_COND(caster == NULL); + ERR_FAIL_COND(!caster || !ObjectDB::instance_validate(caster)); Ref info(memnew(SpellCastInfo())); diff --git a/infos/spell_cast_info.cpp b/infos/spell_cast_info.cpp index b985a7c..46a8dd4 100644 --- a/infos/spell_cast_info.cpp +++ b/infos/spell_cast_info.cpp @@ -4,7 +4,11 @@ //// SpellCastInfo //// -Entity *SpellCastInfo::get_caster() const { +Entity *SpellCastInfo::get_caster() { + if (_caster && !ObjectDB::instance_validate(_caster)) { + _caster = NULL; + } + return _caster; } @@ -26,7 +30,11 @@ void SpellCastInfo::set_caster_bind(Node *caster) { _caster = e; } -Entity *SpellCastInfo::get_target() const { +Entity *SpellCastInfo::get_target() { + if (_target && !ObjectDB::instance_validate(_target)) { + _target = NULL; + } + return _target; } diff --git a/infos/spell_cast_info.h b/infos/spell_cast_info.h index 9641ac4..155c9ad 100644 --- a/infos/spell_cast_info.h +++ b/infos/spell_cast_info.h @@ -11,11 +11,11 @@ class SpellCastInfo : public Reference { GDCLASS(SpellCastInfo, Reference); public: - Entity *get_caster() const; + Entity *get_caster(); void set_caster(Entity *caster); void set_caster_bind(Node *caster); - Entity *get_target() const; + Entity *get_target(); void set_target(Entity *caster); void set_target_bind(Node *caster);