From e55f856fa2e602fa5ceb33e0ecc33d14892ab9d7 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 19 Mar 2022 18:44:49 +0100 Subject: [PATCH] Fixed more potential issues found by the tool. --- .../data/species/species_instance.cpp | 8 +- .../entity_spell_system/data/spells/spell.cpp | 73 +++++++++++++++++-- .../entities/stats/simple_level_stat_data.cpp | 16 ++-- modules/props/prop_instance_prop_job.cpp | 2 + modules/props/prop_mesher.cpp | 16 ++++ 5 files changed, 98 insertions(+), 17 deletions(-) diff --git a/modules/entity_spell_system/data/species/species_instance.cpp b/modules/entity_spell_system/data/species/species_instance.cpp index 93a08374a..143ba60a6 100644 --- a/modules/entity_spell_system/data/species/species_instance.cpp +++ b/modules/entity_spell_system/data/species/species_instance.cpp @@ -40,7 +40,9 @@ int SpeciesInstance::get_species_id() const { void SpeciesInstance::set_species_id(int value) { _id = value; - _species = ESS::get_singleton()->get_resource_db()->get_entity_species_data(_id); + if (ESS::get_singleton()) { + _species = ESS::get_singleton()->get_resource_db()->get_entity_species_data(_id); + } } StringName SpeciesInstance::get_species_path() const { @@ -49,7 +51,9 @@ StringName SpeciesInstance::get_species_path() const { void SpeciesInstance::set_species_path(const StringName &value) { _path = value; - _species = ESS::get_singleton()->get_resource_db()->get_entity_species_data_path(_path); + if (ESS::get_singleton()) { + _species = ESS::get_singleton()->get_resource_db()->get_entity_species_data_path(_path); + } } Ref SpeciesInstance::get_species() { diff --git a/modules/entity_spell_system/data/spells/spell.cpp b/modules/entity_spell_system/data/spells/spell.cpp index f472a63f5..0a1475a2f 100644 --- a/modules/entity_spell_system/data/spells/spell.cpp +++ b/modules/entity_spell_system/data/spells/spell.cpp @@ -1796,6 +1796,9 @@ Spell::~Spell() { } void Spell::_cast_starts(Ref info) { + ERR_FAIL_COND(!info.is_valid()); + ERR_FAIL_COND(!info->caster_get()); + if (info->caster_get()->cast_is_castings()) { return; } @@ -1831,6 +1834,9 @@ void Spell::_cast_starts(Ref info) { } void Spell::_cast_finishs(Ref info) { + ERR_FAIL_COND(!info.is_valid()); + ERR_FAIL_COND(!info->caster_get()); + info->caster_get()->notification_scast(SpellEnums::NOTIFICATION_CAST_FINISHED, info); info->caster_get()->cast_spell_successs(info); @@ -1848,40 +1854,55 @@ void Spell::_cast_finishs(Ref info) { } void Spell::_son_cast_player_moved(Ref info) { + ERR_FAIL_COND(!info.is_valid()); + ERR_FAIL_COND(!info->caster_get()); + if (get_can_move_while_casting()) { info->caster_get()->cast_fails(); } } void Spell::_son_spell_hit(Ref info) { + ERR_FAIL_COND(!info.is_valid()); + handle_effect(info); } void Spell::_calculate_initial_damage(Ref data) { + ERR_FAIL_COND(!data.is_valid()); + Math::randomize(); data->damage_set(damage_get_min() + (damage_get_max() - damage_get_min()) * Math::randf()); } void Spell::_handle_spell_damage(Ref data) { + ERR_FAIL_COND(!data.is_valid()); + calculate_initial_damage(data); data->dealer_get()->sdeal_damage_to(data); } void Spell::_calculate_initial_heal(Ref data) { + ERR_FAIL_COND(!data.is_valid()); + Math::randomize(); data->heal_set(heal_get_min() + (heal_get_max() - heal_get_min()) * Math::randf()); } void Spell::_handle_spell_heal(Ref data) { + ERR_FAIL_COND(!data.is_valid()); + calculate_initial_heal(data); data->dealer_get()->sdeal_heal_to(data); } void Spell::_handle_projectile(Ref info) { + ERR_FAIL_COND(!info.is_valid()); + if (_projectile_scene.is_valid()) { Node *projectile = _projectile_scene->instance(); @@ -1897,6 +1918,8 @@ void Spell::_handle_projectile(Ref info) { } void Spell::_handle_effect(Ref info) { + ERR_FAIL_COND(!info.is_valid()); + /* # var ok : bool = false @@ -2001,6 +2024,7 @@ void Spell::_handle_effect(Ref info) { } void Spell::_aura_sapply(Ref info) { + ERR_FAIL_COND(!info.is_valid()); ERR_FAIL_COND(info->target_get() == NULL || info->caster_get() == NULL || !info->get_aura().is_valid()); Ref ad = info->target_get()->aura_gets_by(info->caster_get(), _id); @@ -2033,6 +2057,7 @@ void Spell::_aura_sapply(Ref info) { } void Spell::_aura_sdeapply(Ref data) { + ERR_FAIL_COND(!data.is_valid()); ERR_FAIL_COND(data->get_owner() == NULL || data->caster_get() == NULL || !data->get_aura().is_valid()); Entity *owner = data->get_owner(); @@ -2053,6 +2078,7 @@ void Spell::_aura_sdeapply(Ref data) { } void Spell::_aura_sadd(Ref aura) { + ERR_FAIL_COND(!aura.is_valid()); ERR_FAIL_COND(aura->get_owner() == NULL); //sapply(aura); @@ -2062,6 +2088,7 @@ void Spell::_aura_sadd(Ref aura) { } void Spell::_aura_sremove(Ref aura) { + ERR_FAIL_COND(!aura.is_valid()); ERR_FAIL_COND(aura->get_owner() == NULL); aura_sdeapply(aura); @@ -2070,6 +2097,7 @@ void Spell::_aura_sremove(Ref aura) { } void Spell::_aura_removes_expired(Ref aura) { + ERR_FAIL_COND(!aura.is_valid()); ERR_FAIL_COND(aura->get_owner() == NULL); aura_sdeapply(aura); @@ -2078,6 +2106,7 @@ void Spell::_aura_removes_expired(Ref aura) { } void Spell::_aura_removes_dispell(Ref aura) { + ERR_FAIL_COND(!aura.is_valid()); ERR_FAIL_COND(aura->get_owner() == NULL); aura_sdeapply(aura); @@ -2086,6 +2115,8 @@ void Spell::_aura_removes_dispell(Ref aura) { } void Spell::_aura_supdate(Ref aura, float delta) { + ERR_FAIL_COND(!aura.is_valid()); + bool remove = false; remove = aura->update(delta); @@ -2121,6 +2152,8 @@ void Spell::_aura_supdate(Ref aura, float delta) { } void Spell::_setup_aura_data(Ref data, Ref info) { + ERR_FAIL_COND(!data.is_valid()); + ERR_FAIL_COND(!info.is_valid()); ERR_FAIL_COND(!ObjectDB::instance_validate(info->caster_get())); data->set_aura(Ref(this)); @@ -2153,20 +2186,32 @@ void Spell::_aura_sapply_passives_damage_deal(Ref info) { } void Spell::_aura_calculate_initial_damage(Ref aura_data, Ref info) { + ERR_FAIL_COND(!aura_data.is_valid()); + ERR_FAIL_COND(!info.is_valid()); + int min_damage = aura_damage_get_min(); int max_damage = aura_damage_get_max(); + int mmm = (max_damage - min_damage); - Math::randomize(); - int damage = min_damage + Math::rand() % (max_damage - min_damage); + int damage = min_damage; - if (aura_get_scale_with_level()) { - damage = static_cast(damage * static_cast(info->caster_get()->gets_level()) / static_cast(ESS::get_singleton()->get_max_character_level())); + if (mmm > 0) { + Math::randomize(); + damage = min_damage + (Math::rand() % mmm); + + if (aura_get_scale_with_level()) { + damage = static_cast(damage * static_cast(info->caster_get()->gets_level()) / static_cast(ESS::get_singleton()->get_max_character_level())); + } } aura_data->damage_set(damage); } void Spell::_handle_aura_damage(Ref aura_data, Ref info) { + ERR_FAIL_COND(!aura_data.is_valid()); + ERR_FAIL_COND(!info.is_valid()); + ERR_FAIL_COND(!info->receiver_get()); + if (info->dealer_get() && !ObjectDB::instance_validate(info->dealer_get())) { info->dealer_set(NULL); } @@ -2190,20 +2235,32 @@ void Spell::_aura_sapply_passives_heal_deal(Ref data) { } void Spell::_aura_calculate_initial_heal(Ref aura_data, Ref info) { + ERR_FAIL_COND(!aura_data.is_valid()); + ERR_FAIL_COND(!info.is_valid()); + int min_heal = aura_heal_get_min(); int max_heal = aura_heal_get_max(); + int mmm = (max_heal - min_heal); - Math::randomize(); - int heal = min_heal + Math::rand() % (max_heal - min_heal); + int heal = min_heal; - if (aura_get_scale_with_level()) { - heal = static_cast(heal * static_cast(info->caster_get()->gets_level()) / static_cast(ESS::get_singleton()->get_max_character_level())); + if (mmm > 0) { + Math::randomize(); + heal = min_heal + (Math::rand() % mmm); + + if (aura_get_scale_with_level()) { + heal = static_cast(heal * static_cast(info->caster_get()->gets_level()) / static_cast(ESS::get_singleton()->get_max_character_level())); + } } aura_data->heal_set(heal); } void Spell::_handle_aura_heal(Ref aura_data, Ref info) { + ERR_FAIL_COND(!aura_data.is_valid()); + ERR_FAIL_COND(!info.is_valid()); + ERR_FAIL_COND(!info->receiver_get()); + if (info->dealer_get() && !ObjectDB::instance_validate(info->dealer_get())) { info->dealer_set(NULL); } diff --git a/modules/entity_spell_system/entities/stats/simple_level_stat_data.cpp b/modules/entity_spell_system/entities/stats/simple_level_stat_data.cpp index c79f63d21..709e79a1b 100644 --- a/modules/entity_spell_system/entities/stats/simple_level_stat_data.cpp +++ b/modules/entity_spell_system/entities/stats/simple_level_stat_data.cpp @@ -25,18 +25,18 @@ SOFTWARE. #include "../../singletons/ess.h" int SimpleLevelStatData::get_stat_per_level(int main_stat) { - ERR_FAIL_INDEX_V(main_stat, ESS::get_singleton()->stat_get_main_stat_count(), 0); + ERR_FAIL_INDEX_V(main_stat, _stat_per_level.size(), 0); return _stat_per_level[main_stat]; } void SimpleLevelStatData::set_stat_per_level(int main_stat, int value) { - ERR_FAIL_INDEX(main_stat, ESS::get_singleton()->stat_get_main_stat_count()); + ERR_FAIL_INDEX(main_stat, _stat_per_level.size()); _stat_per_level.set(main_stat, value); } int SimpleLevelStatData::_get_stat_diff(int main_stat, int old_level, int new_level) { - ERR_FAIL_INDEX_V(main_stat, ESS::get_singleton()->stat_get_main_stat_count(), 0); + ERR_FAIL_INDEX_V(main_stat, _stat_per_level.size(), 0); int s = _stat_per_level[main_stat]; @@ -60,7 +60,7 @@ SimpleLevelStatData::~SimpleLevelStatData() { } bool SimpleLevelStatData::_set(const StringName &p_name, const Variant &p_value) { - if (ESS::get_singleton()->stat_is_property(p_name)) { + if (ESS::get_singleton() && ESS::get_singleton()->stat_is_property(p_name)) { int stat_id = ESS::get_singleton()->stat_get_property_id(p_name); if (stat_id >= ESS::get_singleton()->stat_get_main_stat_count()) { @@ -76,7 +76,7 @@ bool SimpleLevelStatData::_set(const StringName &p_name, const Variant &p_value) } bool SimpleLevelStatData::_get(const StringName &p_name, Variant &r_ret) const { - if (ESS::get_singleton()->stat_is_property(p_name)) { + if (ESS::get_singleton() && ESS::get_singleton()->stat_is_property(p_name)) { int stat_id = ESS::get_singleton()->stat_get_property_id(p_name); if (stat_id >= ESS::get_singleton()->stat_get_main_stat_count()) { @@ -95,8 +95,10 @@ void SimpleLevelStatData::_get_property_list(List *p_list) const { //int property_usange = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL; int property_usange = PROPERTY_USAGE_DEFAULT; - for (int i = 0; i < ESS::get_singleton()->stat_get_main_stat_count(); ++i) { - p_list->push_back(PropertyInfo(Variant::INT, ESS::get_singleton()->stat_get_property_name(i), PROPERTY_HINT_NONE, "", property_usange)); + if (ESS::get_singleton()) { + for (int i = 0; i < ESS::get_singleton()->stat_get_main_stat_count(); ++i) { + p_list->push_back(PropertyInfo(Variant::INT, ESS::get_singleton()->stat_get_property_name(i), PROPERTY_HINT_NONE, "", property_usange)); + } } } diff --git a/modules/props/prop_instance_prop_job.cpp b/modules/props/prop_instance_prop_job.cpp index bfdd03707..b4338e904 100644 --- a/modules/props/prop_instance_prop_job.cpp +++ b/modules/props/prop_instance_prop_job.cpp @@ -208,6 +208,8 @@ void PropInstancePropJob::_reset() { } void PropInstancePropJob::phase_physics_process() { + ERR_FAIL_COND(!_prop_instace); + //TODO this should only update the differences //for (int i = 0; i < _prop_instace->collider_get_num(); ++i) { // PhysicsServer::get_singleton()->free(_prop_instace->collider_body_get(i)); diff --git a/modules/props/prop_mesher.cpp b/modules/props/prop_mesher.cpp index 75f2fcfec..07b650269 100644 --- a/modules/props/prop_mesher.cpp +++ b/modules/props/prop_mesher.cpp @@ -1093,10 +1093,14 @@ void PropMesher::add_vertex(const Vector3 &vertex) { } Vector3 PropMesher::get_vertex(const int idx) const { + ERR_FAIL_INDEX_V(idx, _vertices.size(), Vector3()); + return _vertices.get(idx).vertex; } void PropMesher::remove_vertex(const int idx) { + ERR_FAIL_INDEX(idx, _vertices.size()); + _vertices.remove(idx); } @@ -1128,6 +1132,8 @@ void PropMesher::add_normal(const Vector3 &normal) { } Vector3 PropMesher::get_normal(int idx) const { + ERR_FAIL_INDEX_V(idx, _vertices.size(), Vector3()); + return _vertices.get(idx).normal; } @@ -1159,6 +1165,8 @@ void PropMesher::add_color(const Color &color) { } Color PropMesher::get_color(const int idx) const { + ERR_FAIL_INDEX_V(idx, _vertices.size(), Color()); + return _vertices.get(idx).color; } @@ -1190,6 +1198,8 @@ void PropMesher::add_uv(const Vector2 &uv) { } Vector2 PropMesher::get_uv(const int idx) const { + ERR_FAIL_INDEX_V(idx, _vertices.size(), Vector2()); + return _vertices.get(idx).uv; } @@ -1221,6 +1231,8 @@ void PropMesher::add_uv2(const Vector2 &uv) { } Vector2 PropMesher::get_uv2(const int idx) const { + ERR_FAIL_INDEX_V(idx, _vertices.size(), Vector2()); + return _vertices.get(idx).uv2; } @@ -1241,10 +1253,14 @@ void PropMesher::add_indices(const int index) { } int PropMesher::get_index(const int idx) const { + ERR_FAIL_INDEX_V(idx, _indices.size(), 0); + return _indices.get(idx); } void PropMesher::remove_index(const int idx) { + ERR_FAIL_INDEX(idx, _vertices.size()); + _indices.remove(idx); }