Skip to content

Commit ac90e1b

Browse files
committed
Backends: Win32: replace bd != nullptr assert with early out. (#6275)
+ fixed inconsistent use of break vs return 0 in WndProcHandler (had no tangible effect).
1 parent 0a5d40a commit ac90e1b

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

backends/imgui_impl_win32.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,10 @@ static ImGuiMouseSource GetMouseSourceFromMessageExtraInfo()
582582
IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
583583
{
584584
// Most backends don't have silent checks like this one, but we need it because WndProc are called early in CreateWindow().
585-
if (ImGui::GetCurrentContext() == nullptr)
586-
return 0;
587-
585+
// We silently allow both context or just only backend data to be nullptr.
588586
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
589-
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplWin32_Init()?");
587+
if (bd == nullptr)
588+
return 0;
590589
ImGuiIO& io = ImGui::GetIO();
591590

592591
switch (msg)
@@ -609,10 +608,10 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
609608
}
610609
POINT mouse_pos = { (LONG)GET_X_LPARAM(lParam), (LONG)GET_Y_LPARAM(lParam) };
611610
if (msg == WM_NCMOUSEMOVE && ::ScreenToClient(hwnd, &mouse_pos) == FALSE) // WM_NCMOUSEMOVE are provided in absolute coordinates.
612-
break;
611+
return 0;
613612
io.AddMouseSourceEvent(mouse_source);
614613
io.AddMousePosEvent((float)mouse_pos.x, (float)mouse_pos.y);
615-
break;
614+
return 0;
616615
}
617616
case WM_MOUSELEAVE:
618617
case WM_NCMOUSELEAVE:
@@ -625,7 +624,7 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
625624
bd->MouseTrackedArea = 0;
626625
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
627626
}
628-
break;
627+
return 0;
629628
}
630629
case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK:
631630
case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK:

docs/CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Other changes:
4949
- Backends: all backends + demo now call IMGUI_CHECKVERSION() to verify ABI compatibility between caller
5050
code and compiled version of Dear ImGui. If you get an assert it most likely mean you have a build issue,
5151
read comments near the assert. (#7568)
52+
- Backends: Win32: undo an assert introduced in 1.90.6 which didn't allow WndProc
53+
handler to be called before backend initialization. Because of how ::CreateWindow()
54+
calls in WndProc this is facilitating. (#6275) [@MennoVink]
5255

5356

5457
-----------------------------------------------------------------------

imgui_widgets.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4506,6 +4506,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
45064506
const bool is_cancel = Shortcut(ImGuiKey_Escape, id, f_repeat) || (nav_gamepad_active && Shortcut(ImGuiKey_NavGamepadCancel, id, f_repeat));
45074507

45084508
// FIXME: Should use more Shortcut() and reduce IsKeyPressed()+SetKeyOwner(), but requires modifiers combination to be taken account of.
4509+
// FIXME-OSX: Missing support for Alt(option)+Right/Left = go to end of line, or next line if already in end of line.
45094510
if (IsKeyPressed(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); }
45104511
else if (IsKeyPressed(ImGuiKey_RightArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINEEND : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDRIGHT : STB_TEXTEDIT_K_RIGHT) | k_mask); }
45114512
else if (IsKeyPressed(ImGuiKey_UpArrow) && is_multiline) { if (io.KeyCtrl) SetScrollY(draw_window, ImMax(draw_window->Scroll.y - g.FontSize, 0.0f)); else state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTSTART : STB_TEXTEDIT_K_UP) | k_mask); }

0 commit comments

Comments
 (0)