Fix #7606: Game crash when trying to clean up a crashed script
Also fix another possible memory leak
This commit is contained in:

committed by
Niels Martin Hansen

parent
cf354f6668
commit
60cbddbb5f
@@ -89,6 +89,10 @@ void ScriptInstance::Initialize(const char *main_script, const char *instance_na
|
|||||||
/* Create the main-class */
|
/* Create the main-class */
|
||||||
this->instance = new SQObject();
|
this->instance = new SQObject();
|
||||||
if (!this->engine->CreateClassInstance(instance_name, this->controller, this->instance)) {
|
if (!this->engine->CreateClassInstance(instance_name, this->controller, this->instance)) {
|
||||||
|
/* If CreateClassInstance has returned false instance has not been
|
||||||
|
* registered with squirrel, so avoid trying to Release it by clearing it now */
|
||||||
|
delete this->instance;
|
||||||
|
this->instance = nullptr;
|
||||||
this->Died();
|
this->Died();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -154,6 +158,7 @@ void ScriptInstance::Died()
|
|||||||
this->last_allocated_memory = this->GetAllocatedMemory(); // Update cache
|
this->last_allocated_memory = this->GetAllocatedMemory(); // Update cache
|
||||||
|
|
||||||
if (this->instance != nullptr) this->engine->ReleaseObject(this->instance);
|
if (this->instance != nullptr) this->engine->ReleaseObject(this->instance);
|
||||||
|
delete this->instance;
|
||||||
delete this->engine;
|
delete this->engine;
|
||||||
this->instance = nullptr;
|
this->instance = nullptr;
|
||||||
this->engine = nullptr;
|
this->engine = nullptr;
|
||||||
|
Reference in New Issue
Block a user