From a75e403b35a9365678c439a3c0ffc63e68f43210 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 15 Jun 2021 13:51:16 +0200 Subject: [PATCH] Fixes --- Source/Engine/Content/Asset.cpp | 10 ++++++---- Source/Engine/Content/AssetReference.h | 17 +++++++++++++++++ Source/Engine/Content/WeakAssetReference.h | 17 +++++++++++++++++ Source/Engine/Render2D/FontManager.cpp | 2 +- .../UI/GUI/Common/RenderToTextureControl.cs | 2 ++ Source/Engine/UI/GUI/Common/RichTextBoxBase.cs | 9 +++++---- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Source/Engine/Content/Asset.cpp b/Source/Engine/Content/Asset.cpp index 4614f33cf..e8536f58d 100644 --- a/Source/Engine/Content/Asset.cpp +++ b/Source/Engine/Content/Asset.cpp @@ -20,7 +20,6 @@ AssetReferenceBase::~AssetReferenceBase() _asset->OnLoaded.Unbind(this); _asset->OnUnloaded.Unbind(this); _asset->RemoveReference(); - _asset = nullptr; } } @@ -55,13 +54,15 @@ void AssetReferenceBase::OnSet(Asset* asset) void AssetReferenceBase::OnLoaded(Asset* asset) { - ASSERT(_asset == asset); + if (_asset != asset) + return; Loaded(); } void AssetReferenceBase::OnUnloaded(Asset* asset) { - ASSERT(_asset == asset); + if (_asset != asset) + return; Unload(); OnSet(nullptr); } @@ -92,7 +93,8 @@ void WeakAssetReferenceBase::OnSet(Asset* asset) void WeakAssetReferenceBase::OnUnloaded(Asset* asset) { - ASSERT(_asset == asset); + if (_asset != asset) + return; Unload(); asset->OnUnloaded.Unbind(this); _asset = nullptr; diff --git a/Source/Engine/Content/AssetReference.h b/Source/Engine/Content/AssetReference.h index 68adf4a25..90f472fd6 100644 --- a/Source/Engine/Content/AssetReference.h +++ b/Source/Engine/Content/AssetReference.h @@ -35,6 +35,7 @@ public: EventType Changed; public: + NON_COPYABLE(AssetReferenceBase); /// /// Initializes a new instance of the class. @@ -114,6 +115,22 @@ public: OnSet(other.Get()); } + AssetReference(AssetReference&& other) + { + OnSet(other.Get()); + other.OnSet(nullptr); + } + + AssetReference& operator=(AssetReference&& other) + { + if (&other != this) + { + OnSet(other.Get()); + other.OnSet(nullptr); + } + return *this; + } + /// /// Finalizes an instance of the class. /// diff --git a/Source/Engine/Content/WeakAssetReference.h b/Source/Engine/Content/WeakAssetReference.h index 7e4202fe4..678e2b998 100644 --- a/Source/Engine/Content/WeakAssetReference.h +++ b/Source/Engine/Content/WeakAssetReference.h @@ -25,6 +25,7 @@ public: EventType Unload; public: + NON_COPYABLE(WeakAssetReferenceBase); /// /// Initializes a new instance of the class. @@ -100,6 +101,22 @@ public: OnSet(other.Get()); } + WeakAssetReference(WeakAssetReference&& other) + { + OnSet(other.Get()); + other.OnSet(nullptr); + } + + WeakAssetReference& operator=(WeakAssetReference&& other) + { + if (&other != this) + { + OnSet(other.Get()); + other.OnSet(nullptr); + } + return *this; + } + /// /// Finalizes an instance of the class. /// diff --git a/Source/Engine/Render2D/FontManager.cpp b/Source/Engine/Render2D/FontManager.cpp index a8e16f715..79ab045da 100644 --- a/Source/Engine/Render2D/FontManager.cpp +++ b/Source/Engine/Render2D/FontManager.cpp @@ -109,7 +109,7 @@ void FontManagerService::Dispose() FontTextureAtlas* FontManager::GetAtlas(int32 index) { - return index >= 0 && index < Atlases.Count() ? Atlases.Get()[index] : nullptr; + return index >= 0 && index < Atlases.Count() ? Atlases.Get()[index].Get() : nullptr; } bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) diff --git a/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs b/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs index e2e1532f3..5e3978cd7 100644 --- a/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs +++ b/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs @@ -95,6 +95,8 @@ namespace FlaxEngine.GUI return; } } + if (!_texture || !_texture.IsAllocated) + return; Profiler.BeginEventGPU("RenderToTextureControl"); var context = GPUDevice.Instance.MainContext; diff --git a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs index 0dcfdd797..2cfe11fff 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs @@ -241,11 +241,12 @@ namespace FlaxEngine.GUI // Calculate text blocks for drawing var textBlocks = Utils.ExtractArrayFromList(_textBlocks); + var textBlocksCount = _textBlocks?.Count ?? 0; var hasSelection = HasSelection; var selection = new TextRange(SelectionLeft, SelectionRight); var viewRect = new Rectangle(_viewOffset, Size).MakeExpanded(10.0f); - var firstTextBlock = _textBlocks.Count; - for (int i = 0; i < _textBlocks.Count; i++) + var firstTextBlock = textBlocksCount; + for (int i = 0; i < textBlocksCount; i++) { ref TextBlock textBlock = ref textBlocks[i]; if (textBlock.Bounds.Intersects(ref viewRect)) @@ -254,8 +255,8 @@ namespace FlaxEngine.GUI break; } } - var endTextBlock = Mathf.Min(firstTextBlock + 1, _textBlocks.Count); - for (int i = _textBlocks.Count - 1; i > firstTextBlock; i--) + var endTextBlock = Mathf.Min(firstTextBlock + 1, textBlocksCount); + for (int i = textBlocksCount - 1; i > firstTextBlock; i--) { ref TextBlock textBlock = ref textBlocks[i]; if (textBlock.Bounds.Intersects(ref viewRect))