From 67d84489155d319588701c0edb0001da221d24ae Mon Sep 17 00:00:00 2001 From: JeffR Date: Thu, 9 Jun 2022 16:29:32 -0500 Subject: [PATCH] Fixes cleanup handling on guiBitmapButtonCtrl and guiGameSettingsCtrl to release the bound textures like other GUI controls when they sleep, avoiding a texture object leak. Fixes a call for UINavigation to getPageCount that was erroneously referencing the pageStack Fixes fetch and binding of the image for display when using the uvEditor --- .../source/gui/buttons/guiBitmapButtonCtrl.cpp | 3 +++ .../source/gui/controls/guiGameSettingsCtrl.cpp | 17 +++++++++++++++++ .../source/gui/controls/guiGameSettingsCtrl.h | 2 ++ .../game/data/UI/scripts/menuNavigation.tscript | 2 +- .../BaseGame/game/tools/gui/uvEditor.ed.gui | 13 ++++++++++++- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp index c4b059ce8..3976bb4f4 100644 --- a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp @@ -201,6 +201,9 @@ void GuiBitmapButtonCtrl::onSleep() mTextures[ i ].mTextureInactive = NULL; } + if (mBitmapAsset.notNull()) + mBitmap = NULL; + Parent::onSleep(); } diff --git a/Engine/source/gui/controls/guiGameSettingsCtrl.cpp b/Engine/source/gui/controls/guiGameSettingsCtrl.cpp index f608ea83f..8de1f173a 100644 --- a/Engine/source/gui/controls/guiGameSettingsCtrl.cpp +++ b/Engine/source/gui/controls/guiGameSettingsCtrl.cpp @@ -511,8 +511,25 @@ bool GuiGameSettingsCtrl::onWake() if( !Parent::onWake() ) return false; + _setNextBitmap(getNextBitmap()); + _setPreviousBitmap(getPreviousBitmap()); + _setKeybindBitmap(getKeybindBitmap()); + return true; } + +void GuiGameSettingsCtrl::onSleep() +{ + if (mNextBitmapAsset.notNull()) + mNextBitmap = NULL; + if (mPreviousBitmapAsset.notNull()) + mPreviousBitmap = NULL; + if (mKeybindBitmapAsset.notNull()) + mKeybindBitmap = NULL; + + Parent::onSleep(); +} + void GuiGameSettingsCtrl::activate() { if(isSelected() && isEnabled() && (mScriptCallback != StringTable->EmptyString())) diff --git a/Engine/source/gui/controls/guiGameSettingsCtrl.h b/Engine/source/gui/controls/guiGameSettingsCtrl.h index 86a3465f1..8a6a730dc 100644 --- a/Engine/source/gui/controls/guiGameSettingsCtrl.h +++ b/Engine/source/gui/controls/guiGameSettingsCtrl.h @@ -245,6 +245,8 @@ public: /// Callback when the control wakes up. bool onWake(); + void onSleep(); + void clear(); virtual void onMouseMove(const GuiEvent& event); diff --git a/Templates/BaseGame/game/data/UI/scripts/menuNavigation.tscript b/Templates/BaseGame/game/data/UI/scripts/menuNavigation.tscript index 19fef3476..2ff3dc953 100644 --- a/Templates/BaseGame/game/data/UI/scripts/menuNavigation.tscript +++ b/Templates/BaseGame/game/data/UI/scripts/menuNavigation.tscript @@ -75,7 +75,7 @@ function UINavigation::pushPage(%this, %newPage, %callback) } //don't re-add pages - if(%this.pageStack.getPageCount() != 0 && + if(%this.getPageCount() != 0 && %this.pageStack.getIndexFromKey(%newPage) != -1) return; diff --git a/Templates/BaseGame/game/tools/gui/uvEditor.ed.gui b/Templates/BaseGame/game/tools/gui/uvEditor.ed.gui index c83c11b67..1dc06502a 100644 --- a/Templates/BaseGame/game/tools/gui/uvEditor.ed.gui +++ b/Templates/BaseGame/game/tools/gui/uvEditor.ed.gui @@ -499,6 +499,15 @@ function UVEditor::showDialog( %this, %applyCallback, %obj, %uv) // Get the preview bitmap. Code copied from Material Selector. %material = %obj.material; + if(!isObject(%material)) + { + %matAssetId = %obj.materialAsset; + if(%matAssetId !$= "") + { + %matAssetDef = AssetDatabase.acquireAsset(%matAssetId); + %material = %matAssetDef.materialDefinitionName; + } + } if( %material.getToneMap(0) $= "" && %material.getDiffuseMap(0) $= "" && !isObject(%material.cubemap) ) { %previewImage = "core/images/warnmat"; @@ -507,13 +516,14 @@ function UVEditor::showDialog( %this, %applyCallback, %obj, %uv) { if( %material.toneMap[0] !$= "" ) %previewImage = %material.getToneMap(0); + else if( %material.getDiffuseMapAsset(0) !$= "" ) + %previewImage = %material.getDiffuseMapAsset(0); else if( %material.getDiffuseMap(0) !$= "" ) %previewImage = %material.getDiffuseMap(0); else if( %material.cubemap.cubeFace[0] !$= "" ) %previewImage = %material.cubemap.cubeFace[0]; } - UVEditor-->bitmapPreview.setBitmap(getAssetPreviewImage(%previewImage)); // Set up the color popup %popup = UVEditor-->colorPopup; @@ -535,6 +545,7 @@ function UVEditor::showDialog( %this, %applyCallback, %obj, %uv) Canvas.pushDialog(UVEditorOverlay); UVEditor.setVisible(1); + UVEditor-->bitmapPreview.setBitmap(getAssetPreviewImage(%previewImage)); } function UVEditor::hideDialog( %this )