segross / UnrealImGui

Unreal plug-in that integrates Dear ImGui framework into Unreal Engine 4.
MIT License
666 stars 211 forks source link

[NetImGui] Crash when running without a renderer #58

Open KABoissonneault opened 3 years ago

KABoissonneault commented 3 years ago

In changelist 0e4fa238985a9883e07cbc32122c4638d310f73e, the LoadTextures in ImGuiModuleManager.cpp was moved from FImGuiModuleManager::AddWidgetToViewport to FImGuiModuleManager::OnContextProxyCreated. Since the proxy seems to be always created on first Tick even without a renderer, this crashes with the following callstack.

    [Inline Frame] UnrealEditor-SlateCore.dll!FSlateBrush::CanRenderResourceObject(UObject *) Line 137  C++
>   UnrealEditor-SlateCore.dll!FSlateBrush::SetResourceObject(UObject * InResourceObject) Line 148  C++
    UnrealEditor-ImGui.dll!FTextureManager::FTextureEntry::FTextureEntry(const FName & InName, UTexture2D * InTexture, bool bAddToRoot) Line 140    C++
    UnrealEditor-ImGui.dll!FTextureManager::CreateTextureInternal(const FName & Name, int Width, int Height, unsigned int SrcBpp, unsigned char * SrcData, TFunction<void __cdecl(unsigned char *)> SrcDataCleanup) Line 68 C++
    UnrealEditor-ImGui.dll!FTextureManager::CreatePlainTextureInternal(const FName & Name, int Width, int Height, const FColor & Color) Line 100    C++
    [Inline Frame] UnrealEditor-ImGui.dll!FTextureManager::InitializeErrorTexture(const FColor &) Line 13   C++
    [Inline Frame] UnrealEditor-ImGui.dll!FImGuiModuleManager::LoadTextures() Line 85   C++
    UnrealEditor-ImGui.dll!FImGuiModuleManager::OnContextProxyCreated(int ContextIndex, FImGuiContextProxy & ContextProxy) Line 232 C++

On this line

if (FSlateApplicationBase::IsInitialized())
{
    return FSlateApplicationBase::Get().GetRenderer()->CanRenderResource(*InResourceObject);
}

With the error:

Exception thrown: read access violation.
FSlateApplicationBase::CurrentBaseApplication.Object->Renderer.Object was nullptr.

To reproduce, I opened the editor with -run=GenerateSoundBanks.