Fixed edge cases for serialization and deserialization of scripts #218

Merged
Pycorax merged 3 commits from SP3-6-c-scripting into main 2022-11-17 17:17:13 +08:00
2 changed files with 4 additions and 4 deletions
Showing only changes of commit 6efbea54e1 - Show all commits

View File

@ -307,7 +307,7 @@ namespace SHADE
SHEventHandle SHScriptEngine::onEntityDestroyed(SHEventPtr eventPtr) SHEventHandle SHScriptEngine::onEntityDestroyed(SHEventPtr eventPtr)
{ {
auto eventData = reinterpret_cast<const SHEventSpec<SHEntityDestroyedEvent>*>(eventPtr.get()); auto eventData = reinterpret_cast<const SHEventSpec<SHEntityDestroyedEvent>*>(eventPtr.get());
csScriptsRemoveAll(eventData->data->eid); csScriptsRemoveAllImmediately(eventData->data->eid, true);
return eventData->handle; return eventData->handle;
} }

View File

@ -402,8 +402,8 @@ namespace SHADE
System::Collections::Generic::List<Script^>^ scriptList = scripts[entity]; System::Collections::Generic::List<Script^>^ scriptList = scripts[entity];
for each (Script ^ script in scriptList) for each (Script ^ script in scriptList)
{ {
// Call OnDestroy only if indicated and also in play mode // Call OnDestroy only if indicated and also if the game has run
if (callOnDestroy) if (callOnDestroy && Application::IsPlaying || Application::IsPaused)
{ {
script->OnDestroy(); script->OnDestroy();
} }
@ -469,7 +469,7 @@ namespace SHADE
script->OnDestroy(); script->OnDestroy();
} }
auto entity = script->Owner.GetEntity(); auto entity = script->Owner.GetEntity();
auto scriptList = scripts[script->Owner.GetEntity()]; auto scriptList = scripts[script->Owner.GetEntity()]; // Unable to find here
scriptList->Remove(script); scriptList->Remove(script);
if (scriptList->Count <= 0) if (scriptList->Count <= 0)
{ {