Skip to content

Commit

Permalink
Fix for OpenGL Server support
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyfreg committed Nov 20, 2024
1 parent 227b1f6 commit 1aee485
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Code/ServerApp/Source/NetImguiServer_RemoteClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ void Client::CaptureImguiInput()
// Keyboard / Gamepads Inputs
// If Dear ImGui Update their enum, must also adjust our enum copy,
// so adding a few check to detect a change
#define EnumKeynameTest(KEYNAME) static_cast<int>(NetImgui::Internal::CmdInput::NetImguiKeys::KEYNAME) == static_cast<int>(ImGuiKey::KEYNAME-ImGuiKey::ImGuiKey_NamedKey_BEGIN), "Update the NetImgui enum to match the updated Dear ImGui enum"
#define EnumKeynameTest(KEYNAME) static_cast<int>(NetImgui::Internal::CmdInput::NetImguiKeys::KEYNAME) == static_cast<int>(ImGuiKey::KEYNAME-ImGuiKey::ImGuiKey_NamedKey_BEGIN), "Update the NetImgui enum to match the updated Dear ImGui enum"
static_assert(NetImgui::Internal::CmdInput::NetImguiKeys::ImGuiKey_COUNT == (ImGuiKey_NamedKey_END-ImGuiKey_NamedKey_BEGIN), "Update the NetImgui enum to match the updated Dear ImGui enum");
static_assert(EnumKeynameTest(ImGuiKey_Tab));
static_assert(EnumKeynameTest(ImGuiKey_Escape));
static_assert(EnumKeynameTest(ImGuiKey_RightSuper));
Expand All @@ -457,7 +458,6 @@ void Client::CaptureImguiInput()
static_assert(EnumKeynameTest(ImGuiKey_GamepadR3));
static_assert(EnumKeynameTest(ImGuiKey_GamepadLStickUp));
static_assert(EnumKeynameTest(ImGuiKey_GamepadRStickRight));
static_assert(NetImgui::Internal::CmdInput::NetImguiKeys::ImGuiKey_COUNT == (ImGuiKey_NamedKey_END-ImGuiKey_NamedKey_BEGIN));

// Save every keydown status to out bitmask
uint64_t valueMask(0);
Expand Down
19 changes: 17 additions & 2 deletions Code/ThirdParty/DearImgui/backends/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ struct ImGui_ImplGlfw_Data
ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }
};

//-------------------------------------------------------------------------------------------------
// @SAMPLE_EDIT : Fix for multi application crash
#ifdef _WIN32
#include <stdio.h>
char HWND_PROP_VIEWPORT_KEY[64]={};
#endif
//-------------------------------------------------------------------------------------------------

// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
Expand Down Expand Up @@ -610,6 +618,13 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
IMGUI_CHECKVERSION();
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
//printf("GLFW_VERSION: %d.%d.%d (%d)", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION, GLFW_VERSION_COMBINED);

//-------------------------------------------------------------------------------------------------
// @SAMPLE_EDIT : Fix for multi application crash
#ifdef _WIN32
snprintf(HWND_PROP_VIEWPORT_KEY, sizeof(HWND_PROP_VIEWPORT_KEY), "IMGUI_VIEWPORT_%016llX", reinterpret_cast<unsigned long long>(window));
#endif
//-------------------------------------------------------------------------------------------------

// Setup backend capabilities flags
ImGui_ImplGlfw_Data* bd = IM_NEW(ImGui_ImplGlfw_Data)();
Expand Down Expand Up @@ -1204,7 +1219,7 @@ static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport)

// GLFW hack: install hook for WM_NCHITTEST message handler
#if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32)
::SetPropA(hwnd, "IMGUI_VIEWPORT", viewport);
::SetPropA(hwnd, HWND_PROP_VIEWPORT_KEY, viewport); // @SAMPLE_EDIT : Fix for multi application crash
vd->PrevWndProc = (WNDPROC)::GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
::SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ImGui_ImplGlfw_WndProc);
#endif
Expand Down Expand Up @@ -1408,7 +1423,7 @@ static LRESULT CALLBACK ImGui_ImplGlfw_WndProc(HWND hWnd, UINT msg, WPARAM wPara
{
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
WNDPROC prev_wndproc = bd->PrevWndProc;
ImGuiViewport* viewport = (ImGuiViewport*)::GetPropA(hWnd, "IMGUI_VIEWPORT");
ImGuiViewport* viewport = (ImGuiViewport*)::GetPropA(hWnd, HWND_PROP_VIEWPORT_KEY); // @SAMPLE_EDIT : Fix for multi application crash
if (viewport != NULL)
if (ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData)
prev_wndproc = vd->PrevWndProc;
Expand Down

0 comments on commit 1aee485

Please sign in to comment.