From 311deb5bc0caff70fe9b0e48574463b3f6a6e5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Fri, 11 Jul 2025 12:28:09 +0200 Subject: [PATCH] Fixed Assets being registered for two IDs, getting Asset for Id 0 now returns null. --- GlitchyEditor/src/EditorContentManager.bf | 24 +++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/GlitchyEditor/src/EditorContentManager.bf b/GlitchyEditor/src/EditorContentManager.bf index 35f456c..a6ff3bc 100644 --- a/GlitchyEditor/src/EditorContentManager.bf +++ b/GlitchyEditor/src/EditorContentManager.bf @@ -365,6 +365,11 @@ class EditorContentManager : IContentManager { Asset asset = null; + if (handle == .Invalid) + { + return null; + } + if (!_handleToAsset.TryGetValue(handle, out asset)) { AssetHandle handleAfterLoading = LoadAsset(handle, blocking); @@ -373,9 +378,10 @@ class EditorContentManager : IContentManager { // TODO: If the asset existed at some point, the cache might still know of it. // Or we store the asset name somewhere else. (For the editor in the asset using it?) - asset = new NewPlaceholderAsset(handle, .Error); - - AssignHandleAndManage(asset, handle); + using(asset = new NewPlaceholderAsset(handle, .Error)) + { + AssignHandleAndManage(asset, handle); + } } } @@ -645,11 +651,7 @@ class EditorContentManager : IContentManager using (_finishedEntriesLock.Enter()) { loadedAsset.Identifier = assetNode.Identifier; - // TODO: AssignHandleAndManage - loadedAsset.[Friend]_contentManager = this; - loadedAsset.[Friend]_handle = handle; - - _handleToAsset.Add(handle, loadedAsset); + AssignHandleAndManage(loadedAsset, handle); _identiferToHandle.Add(loadedAsset.Identifier, handle); file.[Friend]_loadedAsset = loadedAsset; @@ -904,6 +906,12 @@ class EditorContentManager : IContentManager private void AssignHandleAndManage(Asset asset, AssetHandle handle) { + if (_handleToAsset.Remove(asset.Handle)) + { + // We need to remove one ref, but it might be the only one, so defer it. + defer:: asset.ReleaseRef(); + } + if (_handleToAsset.TryGetValue(handle, let existingAsset)) { existingAsset.ReleaseRef();