psydack / uimgui

UImGui (Unity ImGui) is an UPM package for the immediate mode GUI library using ImGui.NET. This project is based on RG.ImGui project.
MIT License
349 stars 55 forks source link

[BUG] Custom Font Crashing Unity #42

Closed simeonradivoev closed 2 years ago

simeonradivoev commented 2 years ago

Describe the bug When using a font atlas configuration with a custom font file, it crashed unity upon starting the game. Even when using a callback as described in the readme, the same crash occurs randomly after multiple starts of the game.

To Reproduce Steps to reproduce the behavior uning config:

  1. Create a new Font Atrals Config
  2. Assign a font to it
  3. Assign it to U Im GUI component
  4. Play the editor/game Steps to reproduce the behavior uning config:
  5. Used described method in readme, create method for custom font loading
  6. Start the game and stop it multiple times

Version/Branch of UImGui: Version: 4.1.0

Unity Version 2021.3.6f1

Render pipeline (URP)

Expected behavior Editor should not crasah

Screenshots image

Code

public class FontLoadingComponent : MonoBehaviour
    {
        public unsafe void LoadFontAwesome(ImGuiIOPtr io)
        {
            var fontPath = $"{Application.persistentDataPath}/Font Awesome 6 Free-Regular-400.otf";
            io.Fonts.AddFontFromFileTTF(fontPath, 18, null, io.Fonts.GetGlyphRangesDefault());
        }
    }

Crash Report

Obtained 31 stack frames
0x00007ffe4955252f (cimgui) igValue_Int
0x000002561a437c57 (Mono JIT Code) (wrapper managed-to-native) ImGuiNET.ImGuiNative:ImFontAtlas_Build (ImGuiNET.ImFontAtlas*)
0x000002561a437a7b (Mono JIT Code) ImGuiNET.ImFontAtlasPtr:Build ()
0x000002561a430f5b (Mono JIT Code) [TextureManager.cs:161] UImGui.Texture.TextureManager:BuildFontAtlas (ImGuiNET.ImGuiIOPtr,UImGui.Assets.FontAtlasConfigAsset&,UnityEngine.Events.UnityEvent`1<ImGuiNET.ImGuiIOPtr>) 
0x000002561a42517b (Mono JIT Code) [UImGui.cs:166] UImGui.UImGui:OnEnable () 
0x00000256cfb14188 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ffe3eebe4b4 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke 
0x00007ffe3edfe764 (mono-2.0-bdwgc) [object.c:3066] do_runtime_invoke 
0x00007ffe3edfe8fc (mono-2.0-bdwgc) [object.c:3113] mono_runtime_invoke 
0x00007ff7dcefdac4 (Unity) scripting_method_invoke
0x00007ff7dcef8644 (Unity) ScriptingInvocation::Invoke
0x00007ff7dcec62b4 (Unity) MonoBehaviour::CallMethodIfAvailable
0x00007ff7dcec4b02 (Unity) MonoBehaviour::AddToManager
0x00007ff7dcec5341 (Unity) MonoBehaviour::AwakeFromLoad
0x00007ff7dcfb374f (Unity) AwakeFromLoadQueue::InvokePersistentManagerAwake
0x00007ff7dcfb41bc (Unity) AwakeFromLoadQueue::PersistentManagerAwakeFromLoad
0x00007ff7dcfb4323 (Unity) AwakeFromLoadQueue::PersistentManagerAwakeFromLoad
0x00007ff7dcbffe58 (Unity) LoadSceneOperation::CompleteAwakeSequence
0x00007ff7dcc008d2 (Unity) LoadSceneOperation::CompletePreloadManagerLoadSceneEditor
0x00007ff7dcc0147b (Unity) LoadSceneOperation::IntegrateMainThread
0x00007ff7dcc05071 (Unity) PreloadManager::UpdatePreloadingSingleStep
0x00007ff7dcc0564f (Unity) PreloadManager::WaitForAllAsyncOperationsToComplete
0x00007ff7ddde4b36 (Unity) EditorSceneManager::RestoreSceneBackups
0x00007ff7ddaf5515 (Unity) PlayerLoopController::EnterPlayMode
0x00007ff7ddb04a67 (Unity) PlayerLoopController::SetIsPlaying
0x00007ff7ddb07e6d (Unity) Application::TickTimer
0x00007ff7ddf537aa (Unity) MainMessageLoop
0x00007ff7ddf5805b (Unity) WinMain
0x00007ff7df2db42e (Unity) __scrt_common_main_seh
0x00007ffedfd07034 (KERNEL32) BaseThreadInitThunk
0x00007ffee0422651 (ntdll) RtlUserThreadStart
simeonradivoev commented 2 years ago

Ah never mind, the old I got it working, it was just the old settings were still in effect when using the custom loading through the script.