55
66namespace Lux ::ImGuiEx {
77
8+ namespace
9+ {
10+ bool IsValidClipRect (const ImRect& rect)
11+ {
12+ return rect.Min .x <= rect.Max .x && rect.Min .y <= rect.Max .y ;
13+ }
14+ }
15+
816 ScopedDisable::ScopedDisable (bool disabled /* = true*/ )
917 {
1018 ImGuiEx::BeginDisabled (disabled);
@@ -24,12 +32,15 @@ namespace Lux::ImGuiEx {
2432 // Fill background wiht nice gradient
2533 const float padding = ImGui::GetStyle ().WindowBorderSize ;
2634 const ImRect windowRect = ImGuiEx::RectExpanded (ImGui::GetCurrentWindow ()->Rect (), -padding, -padding);
27- ImGui::PushClipRect (windowRect.Min , windowRect.Max , false );
28- const ImColor col1 = ImGui::GetStyleColorVec4 (ImGuiCol_PopupBg);// Colors::Theme::backgroundPopup;
29- const ImColor col2 = ImGuiEx::ColourWithMultipliedValue (col1, 0 .8f );
30- ImGui::GetWindowDrawList ()->AddRectFilledMultiColor (windowRect.Min , windowRect.Max , col1, col1, col2, col2);
31- ImGui::GetWindowDrawList ()->AddRect (windowRect.Min , windowRect.Max , ImGuiEx::ColourWithMultipliedValue (col1, 1 .1f ));
32- ImGui::PopClipRect ();
35+ if (IsValidClipRect (windowRect))
36+ {
37+ ImGui::PushClipRect (windowRect.Min , windowRect.Max , false );
38+ const ImColor col1 = ImGui::GetStyleColorVec4 (ImGuiCol_PopupBg);// Colors::Theme::backgroundPopup;
39+ const ImColor col2 = ImGuiEx::ColourWithMultipliedValue (col1, 0 .8f );
40+ ImGui::GetWindowDrawList ()->AddRectFilledMultiColor (windowRect.Min , windowRect.Max , col1, col1, col2, col2);
41+ ImGui::GetWindowDrawList ()->AddRect (windowRect.Min , windowRect.Max , ImGuiEx::ColourWithMultipliedValue (col1, 1 .1f ));
42+ ImGui::PopClipRect ();
43+ }
3344
3445 // Popped in EndPopup()
3546 ImGui::PushStyleColor (ImGuiCol_HeaderHovered, IM_COL32 (0 , 0 , 0 , 80 ));
@@ -68,6 +79,15 @@ namespace Lux::ImGuiEx {
6879 IM_ROUND (ImMax (bar_rect.Min .x + window->Pos .x , bar_rect.Max .x - ImMax (window->WindowRounding , window->WindowBorderSize ))), IM_ROUND (bar_rect.Max .y + window->Pos .y ));
6980
7081 clip_rect.ClipWith (window->OuterRectClipped );
82+ if (!IsValidClipRect (clip_rect))
83+ {
84+ ImGuiContext& g = *GImGui;
85+ ImGui::PopID ();
86+ g.GroupStack .back ().EmitItem = false ;
87+ ImGui::EndGroup ();
88+ return false ;
89+ }
90+
7191 ImGui::PushClipRect (clip_rect.Min , clip_rect.Max , false );
7292
7393 // We overwrite CursorMaxPos because BeginGroup sets it to CursorPos (essentially the .EmitItem hack in EndMenuBar() would need something analogous here, maybe a BeginGroupEx() with flags).
@@ -681,6 +701,9 @@ namespace Lux::ImGuiEx {
681701 ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
682702 ImVec2 rectMin, ImVec2 rectMax, ImVec2 uv0, ImVec2 uv1)
683703 {
704+ if (rectMin.x > rectMax.x || rectMin.y > rectMax.y )
705+ return ;
706+
684707 auto * drawList = ImGui::GetWindowDrawList ();
685708 if (ImGui::IsItemActive ())
686709 drawList->AddImage (GetTextureID (imagePressed), rectMin, rectMax, uv0, uv1, tintPressed);
@@ -694,6 +717,9 @@ namespace Lux::ImGuiEx {
694717 ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
695718 ImVec2 rectMin, ImVec2 rectMax, ImVec2 uv0, ImVec2 uv1)
696719 {
720+ if (rectMin.x > rectMax.x || rectMin.y > rectMax.y )
721+ return ;
722+
697723 auto * drawList = ImGui::GetWindowDrawList ();
698724 if (ImGui::IsItemActive ())
699725 drawList->AddImage (GetTextureID (imagePressed), rectMin, rectMax, uv0, uv1, tintPressed);
0 commit comments