File: 0025-Fix-Imgui-FTBFS.patch

package info (click to toggle)
open3d 0.19.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,496 kB
  • sloc: cpp: 206,543; python: 27,254; ansic: 8,356; javascript: 1,883; sh: 1,527; makefile: 259; xml: 69
file content (348 lines) | stat: -rw-r--r-- 17,448 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
From: Anton Gladky <gladk@debian.org>
Date: Tue, 2 Sep 2025 11:26:34 +0200
Subject: fix FTBFS with libimgui-dev 1.92.2b+ds-1

Bug-Debian: https://bugs.debian.org/1112450
Last-Update: 2025-08-31
---
 cpp/open3d/visualization/gui/Button.cpp            |   5 +-
 cpp/open3d/visualization/gui/ImageWidget.cpp       |   6 +-
 .../visualization/gui/ImguiFilamentBridge.cpp      |  11 ++-
 cpp/open3d/visualization/gui/Label.cpp             |   8 +-
 cpp/open3d/visualization/gui/Layout.cpp            |   8 +-
 cpp/open3d/visualization/gui/SceneWidget.cpp       |   5 +-
 cpp/open3d/visualization/gui/Widget.cpp            |   4 +-
 cpp/open3d/visualization/gui/Window.cpp            | 103 +++++++++++++++------
 8 files changed, 101 insertions(+), 49 deletions(-)

diff --git a/cpp/open3d/visualization/gui/Button.cpp b/cpp/open3d/visualization/gui/Button.cpp
index f87a345..a17a71e 100644
--- a/cpp/open3d/visualization/gui/Button.cpp
+++ b/cpp/open3d/visualization/gui/Button.cpp
@@ -8,6 +8,7 @@
 #include "open3d/visualization/gui/Button.h"
 
 #include <imgui.h>
+#include <cstdint>
 
 #include <cmath>
 #include <string>
@@ -142,9 +143,9 @@ Widget::DrawResult Button::Draw(const DrawContext& context) {
     if (impl_->image_) {
         auto params = impl_->image_->CalcDrawParams(context.renderer, frame);
         ImTextureID image_id =
-                reinterpret_cast<ImTextureID>(params.texture.GetId());
+                (ImTextureID)(intptr_t)params.texture.GetId();
         pressed = ImGui::ImageButton(
-                image_id, ImVec2(params.width, params.height),
+                impl_->id_.c_str(), image_id, ImVec2(params.width, params.height),
                 ImVec2(params.u0, params.v0), ImVec2(params.u1, params.v1));
     } else {
         pressed = ImGui::Button(
diff --git a/cpp/open3d/visualization/gui/ImageWidget.cpp b/cpp/open3d/visualization/gui/ImageWidget.cpp
index 5287791..c15a235 100644
--- a/cpp/open3d/visualization/gui/ImageWidget.cpp
+++ b/cpp/open3d/visualization/gui/ImageWidget.cpp
@@ -8,6 +8,7 @@
 #include "open3d/visualization/gui/ImageWidget.h"
 
 #include <imgui.h>
+#include <cstdint>
 
 #include "open3d/geometry/Image.h"
 #include "open3d/visualization/gui/Theme.h"
@@ -99,8 +100,9 @@ Widget::DrawResult ImageWidget::Draw(const DrawContext& context) {
     }
 
     if (params.texture != visualization::rendering::TextureHandle::kBad) {
-        ImTextureID image_id =
-                reinterpret_cast<ImTextureID>(params.texture.GetId());
+        // Cast texture handle to ImTextureID in a way that works whether
+        // ImTextureID is an integer or a pointer type across ImGui versions.
+        ImTextureID image_id = (ImTextureID)(intptr_t)params.texture.GetId();
         ImGui::SetCursorScreenPos(
                 ImVec2(params.pos_x, params.pos_y - ImGui::GetScrollY()));
         ImGui::Image(image_id, ImVec2(params.width, params.height),
diff --git a/cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp b/cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp
index 21a81a7..c599fd6 100644
--- a/cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp
+++ b/cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp
@@ -46,6 +46,7 @@
 #include <imgui.h>
 
 #include <cerrno>
+#include <cstdint>
 #include <iostream>
 #include <map>
 #include <vector>
@@ -294,7 +295,7 @@ void ImguiFilamentBridge::Update(ImDrawData* imgui_data) {
         num_prims += cmds->CmdBuffer.size();
         for (const auto& pcmd : cmds->CmdBuffer) {
             scissor_rects[ScissorRectKey(fbheight, pcmd.ClipRect,
-                                         pcmd.TextureId)] = nullptr;
+                                        pcmd.GetTexID())] = nullptr;
         }
     }
     auto rbuilder = RenderableManager::Builder(num_prims);
@@ -312,7 +313,9 @@ void ImguiFilamentBridge::Update(ImDrawData* imgui_data) {
             // as the default when we created this material.
         } else {
             pair.second = impl_->image_pool_.pull();
-            auto tex_id_long = reinterpret_cast<uintptr_t>(pair.first.id_);
+            // Convert ImTextureID back to an integer ID. This works whether
+            // ImTextureID is a pointer or an integer type.
+            uintptr_t tex_id_long = (uintptr_t)pair.first.id_;
             auto tex_id = std::uint16_t(tex_id_long);
             auto tex_handle = visualization::rendering::TextureHandle(tex_id);
             auto tex = visualization::rendering::EngineInstance::
@@ -337,12 +340,12 @@ void ImguiFilamentBridge::Update(ImDrawData* imgui_data) {
                 buffer_index, cmds->VtxBuffer.Size * sizeof(ImDrawVert),
                 cmds->VtxBuffer.Data, cmds->IdxBuffer.Size * sizeof(ImDrawIdx),
                 cmds->IdxBuffer.Data);
-        for (const auto& pcmd : cmds->CmdBuffer) {
+    for (const auto& pcmd : cmds->CmdBuffer) {
             if (pcmd.UserCallback) {
                 pcmd.UserCallback(cmds, &pcmd);
             } else {
                 auto skey =
-                        ScissorRectKey(fbheight, pcmd.ClipRect, pcmd.TextureId);
+                        ScissorRectKey(fbheight, pcmd.ClipRect, pcmd.GetTexID());
                 auto miter = scissor_rects.find(skey);
                 if (miter != scissor_rects.end()) {
                     rbuilder.geometry(
diff --git a/cpp/open3d/visualization/gui/Label.cpp b/cpp/open3d/visualization/gui/Label.cpp
index 253c390..45f568d 100644
--- a/cpp/open3d/visualization/gui/Label.cpp
+++ b/cpp/open3d/visualization/gui/Label.cpp
@@ -73,7 +73,7 @@ Size Label::CalcPreferredSize(const LayoutContext& context,
     if (impl_->is_single_line) {
         float wrap_width = float(constraints.width);
         auto size =
-                font->CalcTextSizeA(font->FontSize, float(constraints.width),
+                font->CalcTextSizeA(ImGui::GetFontSize(), float(constraints.width),
                                     wrap_width, impl_->text_.c_str());
         pref = Size(int(std::ceil(size.x + 2.0f * padding.x)),
                     int(std::ceil(size.y + 2.0f * padding.y)));
@@ -81,7 +81,7 @@ Size Label::CalcPreferredSize(const LayoutContext& context,
         ImVec2 size(0, 0);
         size_t line_start = 0;
         auto line_end = impl_->text_.find('\n');
-        auto em = int(std::round(font->FontSize));
+        auto em = int(std::round(ImGui::GetFontSize()));
         float wrap_width = float(
                 std::min(constraints.width, PREFERRED_WRAP_WIDTH_EM * em));
         float spacing = ImGui::GetTextLineHeightWithSpacing() -
@@ -89,11 +89,11 @@ Size Label::CalcPreferredSize(const LayoutContext& context,
         do {
             ImVec2 sz;
             if (line_end == std::string::npos) {
-                sz = font->CalcTextSizeA(font->FontSize, FLT_MAX, wrap_width,
+                sz = font->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, wrap_width,
                                          impl_->text_.c_str() + line_start);
                 line_start = line_end;
             } else {
-                sz = font->CalcTextSizeA(font->FontSize, FLT_MAX, wrap_width,
+                sz = font->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, wrap_width,
                                          impl_->text_.c_str() + line_start,
                                          impl_->text_.c_str() + line_end);
                 line_start = line_end + 1;
diff --git a/cpp/open3d/visualization/gui/Layout.cpp b/cpp/open3d/visualization/gui/Layout.cpp
index f8e4fa0..3973511 100644
--- a/cpp/open3d/visualization/gui/Layout.cpp
+++ b/cpp/open3d/visualization/gui/Layout.cpp
@@ -416,10 +416,10 @@ Size CollapsableVert::CalcPreferredSize(const LayoutContext& context,
     auto padding = ImGui::GetStyle().FramePadding;
     int text_height = int(
             std::ceil(ImGui::GetTextLineHeightWithSpacing() + 2 * padding.y));
-    int text_width =
-            int(std::ceil(font->CalcTextSizeA(font->FontSize, FLT_MAX, FLT_MAX,
-                                              impl_->text_.c_str())
-                                  .x));
+    int text_width = int(std::ceil(
+            font->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, FLT_MAX,
+                                impl_->text_.c_str())
+                    .x));
     ImGui::PopFont();  // back to default font for layout sizing
 
     auto pref = Super::CalcPreferredSize(context, constraints);
diff --git a/cpp/open3d/visualization/gui/SceneWidget.cpp b/cpp/open3d/visualization/gui/SceneWidget.cpp
index d0df7af..2cb025c 100644
--- a/cpp/open3d/visualization/gui/SceneWidget.cpp
+++ b/cpp/open3d/visualization/gui/SceneWidget.cpp
@@ -8,6 +8,7 @@
 #include "open3d/visualization/gui/SceneWidget.h"
 
 #include <imgui.h>
+#include <cstdint>
 
 #include <Eigen/Geometry>
 #include <set>
@@ -1125,7 +1126,9 @@ Widget::DrawResult SceneWidget::Draw(const DrawContext& context) {
                          ImGuiWindowFlags_NoBackground);
 
     auto render_tex = impl_->scene_->GetView()->GetColorBuffer();
-    ImTextureID image_id = reinterpret_cast<ImTextureID>(render_tex.GetId());
+    // Cast texture handle to ImTextureID in a way that works whether
+    // ImTextureID is an integer or a pointer type across ImGui versions.
+    ImTextureID image_id = (ImTextureID)(intptr_t)render_tex.GetId();
     ImGui::Image(image_id, ImVec2(f.width, f.height), ImVec2(0.0f, 1.0f),
                  ImVec2(1.0f, 0.0f));
 
diff --git a/cpp/open3d/visualization/gui/Widget.cpp b/cpp/open3d/visualization/gui/Widget.cpp
index d8ab028..b47bf85 100644
--- a/cpp/open3d/visualization/gui/Widget.cpp
+++ b/cpp/open3d/visualization/gui/Widget.cpp
@@ -141,8 +141,8 @@ void Widget::DrawImGuiTooltip() {
         //       seem to get coalesced, so when we pop here, it effectively pops
         //       in calling code, which then crashes because there are too many
         //       pops.
-        float border_radius = std::round(0.2f * ImGui::GetFont()->FontSize);
-        float margin = 0.25f * ImGui::GetFont()->FontSize;
+        float border_radius = std::round(0.2f * ImGui::GetFontSize());
+        float margin = 0.25f * ImGui::GetFontSize();
         float old_radius = ImGui::GetStyle().WindowRounding;
         ImVec2 old_padding = ImGui::GetStyle().WindowPadding;
         ImGui::GetStyle().WindowPadding = ImVec2(2.0f * margin, margin);
diff --git a/cpp/open3d/visualization/gui/Window.cpp b/cpp/open3d/visualization/gui/Window.cpp
index 3c9f2a3..99d9b5b 100644
--- a/cpp/open3d/visualization/gui/Window.cpp
+++ b/cpp/open3d/visualization/gui/Window.cpp
@@ -48,6 +48,52 @@ static constexpr int CENTERED_Y = -10000;
 static constexpr int AUTOSIZE_WIDTH = 0;
 static constexpr int AUTOSIZE_HEIGHT = 0;
 
+static ImGuiKey MapToImGuiKey(uint32_t key) {
+    using namespace open3d::visualization::gui;
+    switch (key) {
+        case KEY_TAB: return ImGuiKey_Tab;
+        case KEY_LEFT: return ImGuiKey_LeftArrow;
+        case KEY_RIGHT: return ImGuiKey_RightArrow;
+        case KEY_UP: return ImGuiKey_UpArrow;
+        case KEY_DOWN: return ImGuiKey_DownArrow;
+        case KEY_PAGEUP: return ImGuiKey_PageUp;
+        case KEY_PAGEDOWN: return ImGuiKey_PageDown;
+        case KEY_HOME: return ImGuiKey_Home;
+        case KEY_END: return ImGuiKey_End;
+        case KEY_INSERT: return ImGuiKey_Insert;
+        case KEY_DELETE: return ImGuiKey_Delete;
+        case KEY_BACKSPACE: return ImGuiKey_Backspace;
+        case KEY_SPACE: return ImGuiKey_Space;
+        case KEY_ENTER: return ImGuiKey_Enter;
+        case KEY_ESCAPE: return ImGuiKey_Escape;
+        case KEY_LSHIFT: return ImGuiKey_LeftShift;
+        case KEY_RSHIFT: return ImGuiKey_RightShift;
+        case KEY_LCTRL: return ImGuiKey_LeftCtrl;
+        case KEY_RCTRL: return ImGuiKey_RightCtrl;
+        case KEY_ALT: return ImGuiKey_LeftAlt;
+        case KEY_META: return ImGuiKey_LeftSuper;
+        case '0': return ImGuiKey_0; case '1': return ImGuiKey_1;
+        case '2': return ImGuiKey_2; case '3': return ImGuiKey_3;
+        case '4': return ImGuiKey_4; case '5': return ImGuiKey_5;
+        case '6': return ImGuiKey_6; case '7': return ImGuiKey_7;
+        case '8': return ImGuiKey_8; case '9': return ImGuiKey_9;
+        case 'A': case 'a': return ImGuiKey_A; case 'B': case 'b': return ImGuiKey_B;
+        case 'C': case 'c': return ImGuiKey_C; case 'D': case 'd': return ImGuiKey_D;
+        case 'E': case 'e': return ImGuiKey_E; case 'F': case 'f': return ImGuiKey_F;
+        case 'G': case 'g': return ImGuiKey_G; case 'H': case 'h': return ImGuiKey_H;
+        case 'I': case 'i': return ImGuiKey_I; case 'J': case 'j': return ImGuiKey_J;
+        case 'K': case 'k': return ImGuiKey_K; case 'L': case 'l': return ImGuiKey_L;
+        case 'M': case 'm': return ImGuiKey_M; case 'N': case 'n': return ImGuiKey_N;
+        case 'O': case 'o': return ImGuiKey_O; case 'P': case 'p': return ImGuiKey_P;
+        case 'Q': case 'q': return ImGuiKey_Q; case 'R': case 'r': return ImGuiKey_R;
+        case 'S': case 's': return ImGuiKey_S; case 'T': case 't': return ImGuiKey_T;
+        case 'U': case 'u': return ImGuiKey_U; case 'V': case 'v': return ImGuiKey_V;
+        case 'W': case 'w': return ImGuiKey_W; case 'X': case 'x': return ImGuiKey_X;
+        case 'Y': case 'y': return ImGuiKey_Y; case 'Z': case 'z': return ImGuiKey_Z;
+        default: return ImGuiKey_None;
+    }
+}
+
 // Assumes the correct ImGuiContext is current
 void UpdateImGuiForScaling(float new_scaling) {
     ImGuiStyle& style = ImGui::GetStyle();
@@ -115,7 +161,8 @@ struct ImguiWindowContext : public FontContext {
         }
         this->imgui_bridge->CreateAtlasTextureAlpha8(pixels, textureW, textureH,
                                                      bytesPerPx);
-        ImGui::SetCurrentFont(this->fonts[Application::DEFAULT_FONT_ID]);
+        ImGui::SetCurrentFont(this->fonts[Application::DEFAULT_FONT_ID],
+                  ImGui::GetFontSize(), ImGui::GetFontSize());
     }
 
     ImFont* AddFont(const FontDescription& fd) {
@@ -338,29 +385,10 @@ Window::Window(const std::string& title,
     ImGuiIO& io = ImGui::GetIO();
     io.IniFilename = nullptr;
 
-    // ImGUI's io.KeysDown is indexed by our scan codes, and we fill out
-    // io.KeyMap to map from our code to ImGui's code.
-    io.KeyMap[ImGuiKey_Tab] = KEY_TAB;
-    io.KeyMap[ImGuiKey_LeftArrow] = KEY_LEFT;
-    io.KeyMap[ImGuiKey_RightArrow] = KEY_RIGHT;
-    io.KeyMap[ImGuiKey_UpArrow] = KEY_UP;
-    io.KeyMap[ImGuiKey_DownArrow] = KEY_DOWN;
-    io.KeyMap[ImGuiKey_PageUp] = KEY_PAGEUP;
-    io.KeyMap[ImGuiKey_PageDown] = KEY_PAGEDOWN;
-    io.KeyMap[ImGuiKey_Home] = KEY_HOME;
-    io.KeyMap[ImGuiKey_End] = KEY_END;
-    io.KeyMap[ImGuiKey_Insert] = KEY_INSERT;
-    io.KeyMap[ImGuiKey_Delete] = KEY_DELETE;
-    io.KeyMap[ImGuiKey_Backspace] = KEY_BACKSPACE;
-    io.KeyMap[ImGuiKey_Space] = ' ';
-    io.KeyMap[ImGuiKey_Enter] = KEY_ENTER;
-    io.KeyMap[ImGuiKey_Escape] = KEY_ESCAPE;
-    io.KeyMap[ImGuiKey_A] = 'a';
-    io.KeyMap[ImGuiKey_C] = 'c';
-    io.KeyMap[ImGuiKey_V] = 'v';
-    io.KeyMap[ImGuiKey_X] = 'x';
-    io.KeyMap[ImGuiKey_Y] = 'y';
-    io.KeyMap[ImGuiKey_Z] = 'z';
+    // ImGUI's io.KeysDown is indexed by our scan codes. In older ImGui
+    // versions we also filled io.KeyMap to translate native codes to
+    // ImGuiKey values. Newer versions removed io.KeyMap.
+
     /*    io.SetClipboardTextFn = [this](void*, const char* text) {
             glfwSetClipboardString(this->impl_->window, text);
         };
@@ -805,10 +833,15 @@ Widget::DrawResult Window::DrawOnce(bool is_layout_pass) {
     io.MouseDown[2] = (buttons & int(MouseButton::MIDDLE));
 
     // Set key information
-    io.KeyShift = (impl_->mouse_mods_ & int(KeyModifier::SHIFT));
-    io.KeyAlt = (impl_->mouse_mods_ & int(KeyModifier::ALT));
-    io.KeyCtrl = (impl_->mouse_mods_ & int(KeyModifier::CTRL));
-    io.KeySuper = (impl_->mouse_mods_ & int(KeyModifier::META));
+    io.AddKeyEvent(ImGuiMod_Shift,
+                   (impl_->mouse_mods_ & int(KeyModifier::SHIFT)) != 0);
+    io.AddKeyEvent(ImGuiMod_Alt,
+                   (impl_->mouse_mods_ & int(KeyModifier::ALT)) != 0);
+    io.AddKeyEvent(ImGuiMod_Ctrl,
+                   (impl_->mouse_mods_ & int(KeyModifier::CTRL)) != 0);
+    io.AddKeyEvent(ImGuiMod_Super,
+                   (impl_->mouse_mods_ & int(KeyModifier::META)) != 0);
+
 
     // Begin an ImGUI frame. We should NOT begin a filament frame here:
     // a) ImGUI always needs to "draw", because event processing happens
@@ -1173,9 +1206,19 @@ void Window::OnKeyEvent(const KeyEvent& e) {
 
     auto old_context = MakeDrawContextCurrent();
     ImGuiIO& io = ImGui::GetIO();
-    if (e.key < IM_ARRAYSIZE(io.KeysDown)) {
-        io.KeysDown[e.key] = (e.type == KeyEvent::DOWN);
+
+    ImGuiKey ik = MapToImGuiKey(e.key);
+    if (ik != ImGuiKey_None) {
+        io.AddKeyEvent(ik, (e.type == KeyEvent::DOWN));
     }
+    io.AddKeyEvent(ImGuiMod_Shift,
+                   (impl_->mouse_mods_ & int(KeyModifier::SHIFT)) != 0);
+    io.AddKeyEvent(ImGuiMod_Alt,
+                   (impl_->mouse_mods_ & int(KeyModifier::ALT)) != 0);
+    io.AddKeyEvent(ImGuiMod_Ctrl,
+                   (impl_->mouse_mods_ & int(KeyModifier::CTRL)) != 0);
+    io.AddKeyEvent(ImGuiMod_Super,
+                   (impl_->mouse_mods_ & int(KeyModifier::META)) != 0);
 
     // If an ImGUI widget is not getting keystrokes, we can send them to
     // non-ImGUI widgets