Fix memory issues.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-03-07 18:20:42 +01:00
parent 7216d9d71b
commit 20f90222d1
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 12 additions and 8 deletions

View File

@ -11,6 +11,12 @@ public:
AngelScriptItemUseScript(asIScriptObject* scriptObject, const AngelScriptResolver* resolver)
: _scriptObject(scriptObject), _resolver(resolver) {}
~AngelScriptItemUseScript(){
if (_scriptObject != nullptr){
_scriptObject->Release();
}
}
[[nodiscard]] bool IsItemUsable() const override;
[[nodiscard]] bool IsCreatureUseItem() const override;
bool IsUseValidForCreature(CreatureLib::Battling::Creature* creature) const override;

View File

@ -34,6 +34,9 @@ private:
public:
~AngelScriptResolver() override {
for (const auto& ius : _itemUseScripts) {
delete ius.second;
}
delete _contextPool;
for (const auto& category : _typeDatabase) {
for (const auto& type : category.second) {

View File

@ -26,6 +26,9 @@ bool IsPokemonUseItem() override {
static AngelScriptResolver* _resolverCache = nullptr;
static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib) {
if (_resolverCache != nullptr) {
delete _resolverCache;
}
_resolverCache = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
_resolverCache->Initialize(mainLib);
for (auto kv : _scripts) {
@ -53,8 +56,6 @@ TEST_CASE("Invoke isItemUsable item use script function on empty class") {
auto script = GetScript(mainLib, "blankClass"_cnc);
REQUIRE(script != nullptr);
REQUIRE_FALSE(script->IsItemUsable());
delete script;
}
TEST_CASE("Invoke isItemUsable item use script function") {
auto mainLib = TestLibrary::GetLibrary();
@ -62,8 +63,6 @@ TEST_CASE("Invoke isItemUsable item use script function") {
auto script = GetScript(mainLib, "isItemUsable"_cnc);
REQUIRE(script != nullptr);
REQUIRE(script->IsItemUsable());
delete script;
}
TEST_CASE("Invoke isPokemonUseItem item use script function on empty class") {
@ -72,8 +71,6 @@ TEST_CASE("Invoke isPokemonUseItem item use script function on empty class") {
auto script = GetScript(mainLib, "blankClass"_cnc);
REQUIRE(script != nullptr);
REQUIRE_FALSE(script->IsCreatureUseItem());
delete script;
}
TEST_CASE("Invoke isPokemonUseItem item use script function") {
auto mainLib = TestLibrary::GetLibrary();
@ -81,8 +78,6 @@ TEST_CASE("Invoke isPokemonUseItem item use script function") {
auto script = GetScript(mainLib, "isPokemonUseItem"_cnc);
REQUIRE(script != nullptr);
REQUIRE(script->IsCreatureUseItem());
delete script;
}
#endif