Fix scripting object issue
This commit is contained in:
@@ -495,7 +495,7 @@ void Scripting::Release()
|
|||||||
{
|
{
|
||||||
auto obj = i->Value;
|
auto obj = i->Value;
|
||||||
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
|
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
|
||||||
LOG(Info, "[OnScriptingDispose] obj = 0x{0:x}, {1}", (uint32)obj.Ptr, String(obj.TypeName));
|
LOG(Info, "[OnScriptingDispose] obj = 0x{0:x}, {1}", (uint64)obj.Ptr, String(obj.TypeName));
|
||||||
#endif
|
#endif
|
||||||
obj->OnScriptingDispose();
|
obj->OnScriptingDispose();
|
||||||
}
|
}
|
||||||
@@ -589,6 +589,24 @@ void Scripting::Reload(bool canTriggerSceneReload)
|
|||||||
MCore::GC::Collect();
|
MCore::GC::Collect();
|
||||||
MCore::GC::WaitForPendingFinalizers();
|
MCore::GC::WaitForPendingFinalizers();
|
||||||
|
|
||||||
|
// Destroy objects from game assemblies (eg. not released objects that might crash if persist in memory after reload)
|
||||||
|
_objectsLocker.Lock();
|
||||||
|
{
|
||||||
|
const auto flaxModule = GetBinaryModuleFlaxEngine();
|
||||||
|
for (auto i = _objectsDictionary.Begin(); i.IsNotEnd(); ++i)
|
||||||
|
{
|
||||||
|
auto obj = i->Value;
|
||||||
|
if (obj->GetTypeHandle().Module == flaxModule)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
|
||||||
|
LOG(Info, "[OnScriptingDispose] obj = 0x{0:x}, {1}", (uint64)obj.Ptr, String(obj.TypeName));
|
||||||
|
#endif
|
||||||
|
obj->OnScriptingDispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_objectsLocker.Unlock();
|
||||||
|
|
||||||
// Unload all game modules
|
// Unload all game modules
|
||||||
LOG(Info, "Unloading game binary modules");
|
LOG(Info, "Unloading game binary modules");
|
||||||
auto modules = BinaryModule::GetModules();
|
auto modules = BinaryModule::GetModules();
|
||||||
@@ -821,7 +839,7 @@ void Scripting::OnManagedInstanceDeleted(ScriptingObject* obj)
|
|||||||
if (_objectsDictionary.ContainsValue(obj))
|
if (_objectsDictionary.ContainsValue(obj))
|
||||||
{
|
{
|
||||||
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
|
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
|
||||||
LOG(Info, "[OnManagedInstanceDeleted] obj = 0x{0:x}, {1}", (uint32)obj, String(ScriptingObjectData(obj).TypeName));
|
LOG(Info, "[OnManagedInstanceDeleted] obj = 0x{0:x}, {1}", (uint64)obj, String(ScriptingObjectData(obj).TypeName));
|
||||||
#endif
|
#endif
|
||||||
obj->OnManagedInstanceDeleted();
|
obj->OnManagedInstanceDeleted();
|
||||||
}
|
}
|
||||||
@@ -877,7 +895,7 @@ void Scripting::RegisterObject(ScriptingObject* obj)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
|
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
|
||||||
LOG(Info, "[RegisterObject] obj = 0x{0:x}, {1}", (uint32)obj, String(ScriptingObjectData(obj).TypeName));
|
LOG(Info, "[RegisterObject] obj = 0x{0:x}, {1}", (uint64)obj, String(ScriptingObjectData(obj).TypeName));
|
||||||
#endif
|
#endif
|
||||||
_objectsDictionary.Add(obj->GetID(), obj);
|
_objectsDictionary.Add(obj->GetID(), obj);
|
||||||
}
|
}
|
||||||
@@ -889,7 +907,7 @@ void Scripting::UnregisterObject(ScriptingObject* obj)
|
|||||||
//ASSERT(!obj->_id.IsValid() || _objectsDictionary.ContainsValue(obj));
|
//ASSERT(!obj->_id.IsValid() || _objectsDictionary.ContainsValue(obj));
|
||||||
|
|
||||||
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
|
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
|
||||||
LOG(Info, "[UnregisterObject] obj = 0x{0:x}, {1}", (uint32)obj, String(ScriptingObjectData(obj).TypeName));
|
LOG(Info, "[UnregisterObject] obj = 0x{0:x}, {1}", (uint64)obj, String(ScriptingObjectData(obj).TypeName));
|
||||||
#endif
|
#endif
|
||||||
_objectsDictionary.Remove(obj->GetID());
|
_objectsDictionary.Remove(obj->GetID());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,10 +276,6 @@ void PersistentScriptingObject::OnManagedInstanceDeleted()
|
|||||||
_gcHandle = 0;
|
_gcHandle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unregister object
|
|
||||||
if (IsRegistered())
|
|
||||||
UnregisterObject();
|
|
||||||
|
|
||||||
// But do not delete itself
|
// But do not delete itself
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user