yasirkula / UnitySimpleFileBrowser

A uGUI based runtime file browser for Unity 3D (draggable and resizable)
MIT License
874 stars 113 forks source link

Changing skin during runtime throws error #81

Closed SchroerDev closed 1 year ago

SchroerDev commented 1 year ago

Description of the bug

Changing skin during runtime throws error when ShowResizeCursor=false:

MissingReferenceException: The variable resizeCursorHandler of FileBrowser doesn't exist anymore.
You probably need to reassign the resizeCursorHandler variable of the 'FileBrowser' script in the inspector.
UnityEngine.Component.GetComponent[T] () (at <86acb61e0d2b4b36bc20af11093be9a5>:0)
SimpleFileBrowser.FileBrowser.RefreshSkin () (at Assets/UnitySimpleFileBrowser/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs:1248)
SimpleFileBrowser.FileBrowser.Update () (at Assets/UnitySimpleFileBrowser/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs:895)

Reproduction steps

  1. Disable the property Show Resize Cursor in file browser prefab
  2. Run in Editor
  3. Open file browser
  4. Select the file browser game object
  5. Change the Skin property in FileBrowser component (e.g from LightSkin to DarkSkin) => Error!

Platform specs

Additional info Filebrowser.cs Line 861 destroys the resizeCursorHandler object and line 1248 calls resizeCursorHandler.GetComponent().

Possible solution Remove:

            Image windowResizeGizmo = resizeCursorHandler.GetComponent<Image>();
            windowResizeGizmo.color = m_skin.WindowResizeGizmoColor;
            windowResizeGizmo.sprite = m_skin.WindowResizeGizmo;

Add:

            if (resizeCursorHandler)
            {
                Image windowResizeGizmo = resizeCursorHandler.GetComponent<Image>();
                windowResizeGizmo.color = m_skin.WindowResizeGizmoColor;
                windowResizeGizmo.sprite = m_skin.WindowResizeGizmo;
            }
yasirkula commented 1 year ago

Thank you for the detailed bug report!

SchroerDev commented 1 year ago

You're welcome! Thank YOU for the great asset!