Fix crash when using audio playback and playing editor meanwhile

This commit is contained in:
Wojtek Figat
2025-03-11 18:10:48 +01:00
parent a3cc3c79e2
commit 3c303514a4
4 changed files with 13 additions and 1 deletions

View File

@@ -606,6 +606,11 @@ void ManagedEditor::WipeOutLeftoverSceneObjects()
{
if (sceneObject->HasParent())
continue; // Skip sub-objects
auto* actor = Cast<Actor>(sceneObject);
if (!actor)
actor = sceneObject->GetParent();
if (actor && actor->HasTag(TEXT("__EditorInternal")))
continue; // Skip internal objects used by Editor (eg. EditorScene)
LOG(Error, "Object '{}' (ID={}, Type={}) is still in memory after play end but should be destroyed (memory leak).", sceneObject->GetNamePath(), sceneObject->GetID(), sceneObject->GetType().ToString());
sceneObject->DeleteObject();

View File

@@ -10,6 +10,9 @@ EditorScene::EditorScene(const SpawnParams& params)
SceneBeginData beginData;
EditorScene::BeginPlay(&beginData);
beginData.OnDone();
// Mark as internal to prevent collection in ManagedEditor::WipeOutLeftoverSceneObjects
Tags.Add(Tags::Get(TEXT("__EditorInternal")));
}
void EditorScene::Update()

View File

@@ -1,6 +1,5 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System.IO;
using System.Xml;
using FlaxEditor.Content;
using FlaxEditor.Content.Import;

View File

@@ -732,7 +732,12 @@ Array<ScriptingObject*, HeapAllocation> Scripting::GetObjects()
{
Array<ScriptingObject*> objects;
_objectsLocker.Lock();
#if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING
for (const auto& e : _objectsDictionary)
objects.Add(e.Value.Ptr);
#else
_objectsDictionary.GetValues(objects);
#endif
_objectsLocker.Unlock();
return objects;
}