UnrealImGui: [Linux] Crash with any text input field
Every time I try to get the focus a text field to type something, I crash in ImGui function ImGui::InputTextEx.
I easily reproduce it with the Demo Window and using the Widgets > Text Input > Resize Callstack example.
LogCore: === Critical error: ===
Unhandled Exception: SIGSEGV: invalid attempt to read memory at address 0x0000000003b37200
LogCore: Fatal error!
libUE4Editor-ImGui.so!ImGui::InputTextEx(char const*, char const*, char*, int, ImVec2 const&, int, int (*)(ImGuiInputTextCallbackData*), void*) [/mnt/dev/Perforce/Exedre/Plugins/ImGui/Source/ThirdParty/ImGuiLibrary/Private/imgui_widgets.cpp:3689]
libUE4Editor-ImGui.so!ShowDemoWindowWidgets() [/mnt/dev/Perforce/Exedre/Plugins/ImGui/Source/ThirdParty/ImGuiLibrary/Private/imgui_demo.cpp:1075]
libUE4Editor-ImGui.so!ImGui::ShowDemoWindow(bool*) [/mnt/dev/Perforce/Exedre/Plugins/ImGui/Source/ThirdParty/ImGuiLibrary/Private/imgui_demo.cpp:428]
libUE4Editor-Exedre.so!UExedreDebugUI::RenderMenu(float) [/mnt/dev/Perforce/Exedre/Source/Exedre/GUI/ExedreDebugUI.cpp:327]
libUE4Editor-Exedre.so!AExedreWidgetManager::UpdateAndRenderMenus(float) [/mnt/dev/Perforce/Exedre/Source/Exedre/GUI/ExedreWidgetManager_Render.cpp:160]
libUE4Editor-Exedre.so!AExedreWidgetManager::ManualTick(float) [/mnt/dev/Perforce/Exedre/Source/Exedre/GUI/ExedreWidgetManager_Base.cpp:287]
libUE4Editor-Engine.so!AHUD::PostRender() [/mnt/dev/UE4/Engine/UnrealEngine_4-25-2/Engine/Source/Runtime/Engine/Private/HUD.cpp:172]
libUE4Editor-Engine.so!UGameViewportClient::Draw(FViewport*, FCanvas*) [/mnt/dev/UE4/Engine/UnrealEngine_4-25-2/Engine/Source/Runtime/Engine/Private/GameViewportClient.cpp:1620]
libUE4Editor-Engine.so!FViewport::Draw(bool) [/mnt/dev/UE4/Engine/UnrealEngine_4-25-2/Engine/Source/Runtime/Engine/Private/UnrealClient.cpp:1541]
libUE4Editor-Engine.so!UGameEngine::RedrawViewports(bool) [/mnt/dev/UE4/Engine/UnrealEngine_4-25-2/Engine/Source/Runtime/Engine/Private/GameEngine.cpp:682]
libUE4Editor-Engine.so!UGameEngine::Tick(float, bool) [/mnt/dev/UE4/Engine/UnrealEngine_4-25-2/Engine/Source/Runtime/Engine/Private/GameEngine.cpp:1806]
UE4Editor-Cmd!FEngineLoop::Tick() [/mnt/dev/UE4/Engine/UnrealEngine_4-25-2/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:4844]
UE4Editor-Cmd!GuardedMain(char16_t const*) [/mnt/dev/UE4/Engine/UnrealEngine_4-25-2/Engine/Source/Runtime/Launch/Private/Launch.cpp:171]
libUE4Editor-UnixCommonStartup.so!CommonUnixMain(int, char**, int (*)(char16_t const*), void (*)()) [/mnt/dev/UE4/Engine/UnrealEngine_4-25-2/Engine/Source/Runtime/Unix/UnixCommonStartup/Private/UnixCommonStartup.cpp:264]
libc.so.6!__libc_start_main(+0xf1)
UE4Editor-Cmd!_start()
Looks like it’s crashing on this line:
if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINESTART : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDLEFT : STB_TEXTEDIT_K_LEFT) | k_mask); }
I gave a try at the standalone ImGui versions 1.78 and 1.74 (via the example example_sdl_opengl2) and it’s not crashing. Any idea what that might be ?
I’m using the following by the way :
FImGuiModule::Get().GetProperties().SetInputEnabled( true );
FImGuiModule::Get().GetProperties().SetKeyboardInputShared( true );
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (10 by maintainers)
+1 on this. I hit this in our application, and the next two levels in the callstack above are actually IsKeyPressedMap and IsKeyPressed due to this line in InputTextEx:
I did dig into the root cause. It’s the values of the keys at the platform-specific level and their use as an index as noted by @Froyok . On Linux, the underlying implementation is using SDL, and not so coincidentally, 1073741904 is 0x40000050, which maps to SDLK_LEFT. Here’s a copy/paste from an internal Jira where I dumped my analysis:
"Ok, yeah, this is a Linux-specific issue. That 1073741904 value is 0x40000050, which maps to SDLK_LEFT (arrow key) in the SDL library (which is what UE4 uses for its underlying Linux implementation), as can be seen here: https://wiki.libsdl.org/SDLKeycodeLookup
They are using that value as a lookup into an array of size 512, so this is going way past valid memory of the array. On Windows, that left arrow key index value is 37, so a safe value.
37 is VK_LEFT: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes … mapped in UE4 here for EKeys::Left: https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/InputCore/Private/Windows/WindowsPlatformInput.cpp#L34 : ADDKEYMAP( VK_LEFT, TEXT(“Left”) );.
0x40000050, on Linux, mapped here as SDKL_LEFT: https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/InputCore/Private/Linux/LinuxPlatformInput.cpp#L31 : ADDKEYMAP(SDLK_LEFT, TEXT(“Left”));
In the ImGui code: KeyMap[ImGuiKey_LeftArrow] = GetKeyIndex(EKeys::Left);
So, this all aligns to end up in the crash we are seeing."
Circling back, since it took a bit of time to get a build finally into Linux-using hands, but we confirm the fix works, and everything works a-ok on Windows still as well (so, no regression issues)! Thanks for kicking this one out, man!
I’m not able to run client but I run a server using WSL and printed values in map. All seem good so closing the bug but feel free to reopen, if you still have problems with this. Thank you for assistance guys.