Fix crash when using network replication or rpc after hot-reload in Editor
This commit is contained in:
@@ -29,6 +29,9 @@
|
||||
#include "Engine/Scripting/ScriptingObjectReference.h"
|
||||
#include "Engine/Threading/Threading.h"
|
||||
#include "Engine/Threading/ThreadLocal.h"
|
||||
#if USE_EDITOR
|
||||
#include "FlaxEngine.Gen.h"
|
||||
#endif
|
||||
|
||||
#if !BUILD_RELEASE
|
||||
bool NetworkReplicator::EnableLog = false;
|
||||
@@ -235,6 +238,33 @@ namespace
|
||||
#endif
|
||||
Array<Guid> DespawnedObjects;
|
||||
uint32 SpawnId = 0;
|
||||
|
||||
#if USE_EDITOR
|
||||
void OnScriptsReloading()
|
||||
{
|
||||
ScopeLock lock(ObjectsLock);
|
||||
if (Objects.HasItems())
|
||||
LOG(Warning, "Hot-reloading scripts with network objects active.");
|
||||
if (Hierarchy)
|
||||
{
|
||||
Delete(Hierarchy);
|
||||
Hierarchy = nullptr;
|
||||
}
|
||||
|
||||
// Clear any references to non-engine scripts before code hot-reload
|
||||
BinaryModule* flaxModule = GetBinaryModuleFlaxEngine();
|
||||
for (auto i = SerializersTable.Begin(); i.IsNotEnd(); ++i)
|
||||
{
|
||||
if (i->Key.Module != flaxModule)
|
||||
SerializersTable.Remove(i);
|
||||
}
|
||||
for (auto i = NetworkRpcInfo::RPCsTable.Begin(); i.IsNotEnd(); ++i)
|
||||
{
|
||||
if (i->Key.First.Module != flaxModule)
|
||||
NetworkRpcInfo::RPCsTable.Remove(i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
class NetworkReplicationService : public EngineService
|
||||
@@ -245,9 +275,18 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
bool Init() override;
|
||||
void Dispose() override;
|
||||
};
|
||||
|
||||
bool NetworkReplicationService::Init()
|
||||
{
|
||||
#if USE_EDITOR
|
||||
Scripting::ScriptsReloading.Bind(OnScriptsReloading);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void NetworkReplicationService::Dispose()
|
||||
{
|
||||
NetworkInternal::NetworkReplicatorClear();
|
||||
|
||||
Reference in New Issue
Block a user