Fix memory issues.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
7216d9d71b
commit
20f90222d1
|
@ -11,6 +11,12 @@ public:
|
||||||
AngelScriptItemUseScript(asIScriptObject* scriptObject, const AngelScriptResolver* resolver)
|
AngelScriptItemUseScript(asIScriptObject* scriptObject, const AngelScriptResolver* resolver)
|
||||||
: _scriptObject(scriptObject), _resolver(resolver) {}
|
: _scriptObject(scriptObject), _resolver(resolver) {}
|
||||||
|
|
||||||
|
~AngelScriptItemUseScript(){
|
||||||
|
if (_scriptObject != nullptr){
|
||||||
|
_scriptObject->Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool IsItemUsable() const override;
|
[[nodiscard]] bool IsItemUsable() const override;
|
||||||
[[nodiscard]] bool IsCreatureUseItem() const override;
|
[[nodiscard]] bool IsCreatureUseItem() const override;
|
||||||
bool IsUseValidForCreature(CreatureLib::Battling::Creature* creature) const override;
|
bool IsUseValidForCreature(CreatureLib::Battling::Creature* creature) const override;
|
||||||
|
|
|
@ -34,6 +34,9 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~AngelScriptResolver() override {
|
~AngelScriptResolver() override {
|
||||||
|
for (const auto& ius : _itemUseScripts) {
|
||||||
|
delete ius.second;
|
||||||
|
}
|
||||||
delete _contextPool;
|
delete _contextPool;
|
||||||
for (const auto& category : _typeDatabase) {
|
for (const auto& category : _typeDatabase) {
|
||||||
for (const auto& type : category.second) {
|
for (const auto& type : category.second) {
|
||||||
|
|
|
@ -26,6 +26,9 @@ bool IsPokemonUseItem() override {
|
||||||
|
|
||||||
static AngelScriptResolver* _resolverCache = nullptr;
|
static AngelScriptResolver* _resolverCache = nullptr;
|
||||||
static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib) {
|
static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib) {
|
||||||
|
if (_resolverCache != nullptr) {
|
||||||
|
delete _resolverCache;
|
||||||
|
}
|
||||||
_resolverCache = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
_resolverCache = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
|
||||||
_resolverCache->Initialize(mainLib);
|
_resolverCache->Initialize(mainLib);
|
||||||
for (auto kv : _scripts) {
|
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);
|
auto script = GetScript(mainLib, "blankClass"_cnc);
|
||||||
REQUIRE(script != nullptr);
|
REQUIRE(script != nullptr);
|
||||||
REQUIRE_FALSE(script->IsItemUsable());
|
REQUIRE_FALSE(script->IsItemUsable());
|
||||||
|
|
||||||
delete script;
|
|
||||||
}
|
}
|
||||||
TEST_CASE("Invoke isItemUsable item use script function") {
|
TEST_CASE("Invoke isItemUsable item use script function") {
|
||||||
auto mainLib = TestLibrary::GetLibrary();
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
@ -62,8 +63,6 @@ TEST_CASE("Invoke isItemUsable item use script function") {
|
||||||
auto script = GetScript(mainLib, "isItemUsable"_cnc);
|
auto script = GetScript(mainLib, "isItemUsable"_cnc);
|
||||||
REQUIRE(script != nullptr);
|
REQUIRE(script != nullptr);
|
||||||
REQUIRE(script->IsItemUsable());
|
REQUIRE(script->IsItemUsable());
|
||||||
|
|
||||||
delete script;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Invoke isPokemonUseItem item use script function on empty class") {
|
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);
|
auto script = GetScript(mainLib, "blankClass"_cnc);
|
||||||
REQUIRE(script != nullptr);
|
REQUIRE(script != nullptr);
|
||||||
REQUIRE_FALSE(script->IsCreatureUseItem());
|
REQUIRE_FALSE(script->IsCreatureUseItem());
|
||||||
|
|
||||||
delete script;
|
|
||||||
}
|
}
|
||||||
TEST_CASE("Invoke isPokemonUseItem item use script function") {
|
TEST_CASE("Invoke isPokemonUseItem item use script function") {
|
||||||
auto mainLib = TestLibrary::GetLibrary();
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
@ -81,8 +78,6 @@ TEST_CASE("Invoke isPokemonUseItem item use script function") {
|
||||||
auto script = GetScript(mainLib, "isPokemonUseItem"_cnc);
|
auto script = GetScript(mainLib, "isPokemonUseItem"_cnc);
|
||||||
REQUIRE(script != nullptr);
|
REQUIRE(script != nullptr);
|
||||||
REQUIRE(script->IsCreatureUseItem());
|
REQUIRE(script->IsCreatureUseItem());
|
||||||
|
|
||||||
delete script;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue