Div0 in ImGuizmo::ComputeContext
Closed this issue · 2 comments
mgerhardy commented
It's about the orthographic mode and shifting on the x axis
Thread 1 "vengi-voxedit" received signal SIGFPE, Arithmetic exception.
ImGuizmo::ComputeContext (view=0x55555859e620, projection=0x55555859e6a0, matrix=0x7fffffffc500, mode=ImGuizmo::LOCAL) at /home/mgerhardy/dev/engine/src/modules/ui/dearimgui/ImGuizmo.cpp:1070
1070 gContext.mScreenFactor = gContext.mGizmoSizeClipSpace / (pointRight.x / pointRight.w - gContext.mMVP.v.position.x / gContext.mMVP.v.position.w);
(gdb) bt
#0 ImGuizmo::ComputeContext (view=0x55555859e620, projection=0x55555859e6a0, matrix=0x7fffffffc500, mode=ImGuizmo::LOCAL) at /home/mgerhardy/dev/engine/src/modules/ui/dearimgui/ImGuizmo.cpp:1070
#1 0x00005555558e5205 in ImGuizmo::Manipulate (view=0x55555859e620, projection=0x55555859e6a0, operation=2047, mode=ImGuizmo::LOCAL, matrix=0x7fffffffc500, deltaMatrix=0x7fffffffc540, snap=0x7fffffffc4e8, localBounds=0x55555859b6dc, boundsSnap=0x7fffffffc4f4)
at /home/mgerhardy/dev/engine/src/modules/ui/dearimgui/ImGuizmo.cpp:2487
#2 0x00005555555b7fd1 in voxedit::Viewport::renderSceneGuizmo (this=0x55555859b680, camera=...) at /home/mgerhardy/dev/engine/src/tools/voxedit/modules/voxedit-ui/Viewport.cpp:324
#3 0x00005555555b8760 in voxedit::Viewport::renderGizmo (this=0x55555859b680, camera=..., headerSize=23.8817329, size=...) at /home/mgerhardy/dev/engine/src/tools/voxedit/modules/voxedit-ui/Viewport.cpp:411
#4 0x00005555555b71f1 in voxedit::Viewport::update (this=0x55555859b680) at /home/mgerhardy/dev/engine/src/tools/voxedit/modules/voxedit-ui/Viewport.cpp:163
#5 0x00005555555a5122 in voxedit::MainWindow::mainWidget (this=0x555557e73750) at /home/mgerhardy/dev/engine/src/tools/voxedit/modules/voxedit-ui/MainWindow.cpp:198
#6 0x00005555555a646e in voxedit::MainWindow::update (this=0x555557e73750) at /home/mgerhardy/dev/engine/src/tools/voxedit/modules/voxedit-ui/MainWindow.cpp:448
#7 0x0000555555599df2 in VoxEdit::onRenderUI (this=0x7fffffffcd70) at /home/mgerhardy/dev/engine/src/tools/voxedit/VoxEdit.cpp:289
#8 0x00005555557c26e6 in ui::IMGUIApp::onRunning (this=0x7fffffffcd70) at /home/mgerhardy/dev/engine/src/modules/ui/IMGUIApp.cpp:388
#9 0x0000555555599e0e in VoxEdit::onRunning (this=0x7fffffffcd70) at /home/mgerhardy/dev/engine/src/tools/voxedit/VoxEdit.cpp:293
#10 0x000055555595f2cf in app::App::onFrame (this=0x7fffffffcd70) at /home/mgerhardy/dev/engine/src/modules/app/App.cpp:165
#11 0x000055555595eefb in app::App::startMainLoop (this=0x7fffffffcd70, argc=1, argv=0x7fffffffdde8) at /home/mgerhardy/dev/engine/src/modules/app/App.cpp:90
#12 0x0000555555599f18 in main (argc=1, argv=0x7fffffffdde8) at /home/mgerhardy/dev/engine/src/tools/voxedit/VoxEdit.cpp:314
(gdb) l
1065 gContext.mReversed = (nearPos.z/nearPos.w) > (farPos.z / farPos.w);
1066
1067 // compute scale from the size of camera right vector projected on screen at the matrix position
1068 vec_t pointRight = viewInverse.v.right;
1069 pointRight.TransformPoint(gContext.mViewProjection);
1070 gContext.mScreenFactor = gContext.mGizmoSizeClipSpace / (pointRight.x / pointRight.w - gContext.mMVP.v.position.x / gContext.mMVP.v.position.w);
1071
1072 vec_t rightViewInverse = viewInverse.v.right;
1073 rightViewInverse.TransformVector(gContext.mModelInverse);
1074 float rightLength = GetSegmentLengthClipSpace(makeVect(0.f, 0.f), rightViewInverse);
(gdb) p pointRight
$1 = {x = -0.393480003, y = -0.721848011, z = -0.96603936, w = 1}
(gdb) p gContext.mMVP.v.position.w
$2 = 1
(gdb) p gContext.mMVP.v.position.x
$3 = -0.393480003
(gdb) p (pointRight.x / pointRight.w - gContext.mMVP.v.position.x / gContext.mMVP.v.position.w)
$4 = 0
(gdb) p gContext.mGizmoSizeClipSpace
$5 = 0.100000001
mgerhardy commented
the interesting fact here is that the value that is computed here is not used at all
it's overwritten a few lines below with a different value... (gContext.mScreenFactor
)
mgerhardy commented
So the fix is this:
diff --git a/src/modules/ui/dearimgui/ImGuizmo.cpp b/src/modules/ui/dearimgui/ImGuizmo.cpp
index 6993c207b..13aa7edc4 100644
--- a/src/modules/ui/dearimgui/ImGuizmo.cpp
+++ b/src/modules/ui/dearimgui/ImGuizmo.cpp
@@ -1067,7 +1067,6 @@ namespace IMGUIZMO_NAMESPACE
// compute scale from the size of camera right vector projected on screen at the matrix position
vec_t pointRight = viewInverse.v.right;
pointRight.TransformPoint(gContext.mViewProjection);
- gContext.mScreenFactor = gContext.mGizmoSizeClipSpace / (pointRight.x / pointRight.w - gContext.mMVP.v.position.x / gContext.mMVP.v.position.w);
vec_t rightViewInverse = viewInverse.v.right;
rightViewInverse.TransformVector(gContext.mModelInverse);