Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Studio segfaults when dynamically resizing objects with the mouse #516

Open
wridgers opened this issue Dec 2, 2022 · 1 comment
Open
Labels

Comments

@wridgers
Copy link
Contributor

wridgers commented Dec 2, 2022

Description

With CMAKE_BUILD_TYPE=RelWithDbgInfo or Debug, Studio segfaults when dynamically resizing objects with the mouse.

The charm.io example reproduces this bug reliably for me:

(define (sphere r)
  (lambda-shape (x y z)
    (- (sqrt (+ (* x x)
                (* y y)
                (* z z))) r)))

;; Numbers that are prefixed by a octothorpe
;; (#) are interpreted as free variables.
;; Dragging the model's surface in the 3D
;; viewport will automatically update the value
;; of the variable in the script.
(define-shape (cutout x y z)
  (let ((r #0.2))
  (max (- r (abs x))
       (- r (abs y))
       (- r (abs z)))))

;; There's not always a valid solution!
;; The inner sphere's radius isn't free in the
;; code below; if you drag it, you should see
;; the model turn red, indicating that no
;; solution was found.
(max (sphere #1)
     (- cutout)
     (- (sphere 0.8)))

(set-quality! 8)
(set-resolution! 10)
(set-bounds! [-10 -10 -10] [10 10 10])

Click and drag a model face in the preview after to resize the model. It works, but segfaults reliably after a second or so.

Studio: /home/w/src/libfive/studio/src/shape.cpp:60: bool Studio::Shape::updateFrom(const Studio::Shape*): Assertion `other->id() == id()' failed.
[1]    1210780 IOT instruction (core dumped)  ./build/studio/Studio

>>> bt
#0  0x00007f82e9cb0fac in ?? () from /lib64/libc.so.6
#1  0x00007f82e9c63b62 in raise () from /lib64/libc.so.6
#2  0x00007f82e9c4e471 in abort () from /lib64/libc.so.6
#3  0x00007f82e9c4e395 in ?? () from /lib64/libc.so.6
#4  0x00007f82e9c5cb12 in __assert_fail () from /lib64/libc.so.6
#5  0x00005631866e958d in Studio::Shape::updateFrom (this=0x7f82d0037090, other=0x7f82d002f810) at /home/w/src/libfive/studio/src/shape.cpp:60
#6  0x00005631866faf47 in Studio::View::setShapes (this=0x5631870affb0, new_shapes=...) at /home/w/src/libfive/studio/src/view.cpp:107
#7  0x000056318671405c in QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<QList<Studio::Shape*> >, void, void (Studio::View::*)(QList<Studio::Shape*>)>::call (f=(void (Studio::View::*)(Studio::View * const, QList<Studio::Shape*>)) 0x5631866fab14 <Studio::View::setShapes(QList<Studio::Shape*>)>, o=0x5631870affb0, arg=0x7ffff84fa9f0) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:152
#8  0x00005631867135ba in QtPrivate::FunctionPointer<void (Studio::View::*)(QList<Studio::Shape*>)>::call<QtPrivate::List<QList<Studio::Shape*> >, void> (f=(void (Studio::View::*)(Studio::View * const, QList<Studio::Shape*>)) 0x5631866fab14 <Studio::View::setShapes(QList<Studio::Shape*>)>, o=0x5631870affb0, arg=0x7ffff84fa9f0) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:185
#9  0x0000563186712d07 in QtPrivate::QSlotObject<void (Studio::View::*)(QList<Studio::Shape*>), QtPrivate::List<QList<Studio::Shape*> >, void>::impl (which=1, this_=0x5631871a5110, r=0x5631870affb0, a=0x7ffff84fa9f0, ret=0x0) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:418
#10 0x00007f82ea0b42f6 in ?? () from /usr/lib64/libQt5Core.so.5
#11 0x00005631866c0e8c in Studio::Editor::shapes (this=0x563187053020, _t1=...) at /home/w/src/libfive/build/studio/Studio_autogen/UBM2Q4CEWX/moc_editor.cpp:317
#12 0x00005631866df601 in Studio::Editor::onInterpreterDone (this=0x563187053020, r=...) at /home/w/src/libfive/studio/src/editor.cpp:143
#13 0x00005631866e61d3 in QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<Studio::Result>, void, void (Studio::Editor::*)(Studio::Result)>::call (f=(void (Studio::Editor::*)(Studio::Editor * const, Studio::Result)) 0x5631866df43c <Studio::Editor::onInterpreterDone(Studio::Result)>, o=0x563187053020, arg=0x7ffff84fad50) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:152
#14 0x00005631866e5da8 in QtPrivate::FunctionPointer<void (Studio::Editor::*)(Studio::Result)>::call<QtPrivate::List<Studio::Result>, void> (f=(void (Studio::Editor::*)(Studio::Editor * const, Studio::Result)) 0x5631866df43c <Studio::Editor::onInterpreterDone(Studio::Result)>, o=0x563187053020, arg=0x7ffff84fad50) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:185
#15 0x00005631866e5653 in QtPrivate::QSlotObject<void (Studio::Editor::*)(Studio::Result), QtPrivate::List<Studio::Result>, void>::impl (which=1, this_=0x56318749cd70, r=0x563187053020, a=0x7ffff84fad50, ret=0x0) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:418
#16 0x00007f82ea0b42f6 in ?? () from /usr/lib64/libQt5Core.so.5
#17 0x00005631866c1c6a in Studio::Language::interpreterDone (this=0x5631874ad990, _t1=...) at /home/w/src/libfive/build/studio/Studio_autogen/UBM2Q4CEWX/moc_language.cpp:210
#18 0x00005631866e8453 in QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<Studio::Result>, void, void (Studio::Language::*)(Studio::Result)>::call (f=(void (Studio::Language::*)(Studio::Language * const, Studio::Result)) 0x5631866c1c0c <Studio::Language::interpreterDone(Studio::Result)>, o=0x5631874ad990, arg=0x7f82d022e0e8) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:152
#19 0x00005631866e80d2 in QtPrivate::FunctionPointer<void (Studio::Language::*)(Studio::Result)>::call<QtPrivate::List<Studio::Result>, void> (f=(void (Studio::Language::*)(Studio::Language * const, Studio::Result)) 0x5631866c1c0c <Studio::Language::interpreterDone(Studio::Result)>, o=0x5631874ad990, arg=0x7f82d022e0e8) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:185
#20 0x00005631866e7dd7 in QtPrivate::QSlotObject<void (Studio::Language::*)(Studio::Result), QtPrivate::List<Studio::Result>, void>::impl (which=1, this_=0x5631870db4d0, r=0x5631874ad990, a=0x7f82d022e0e8, ret=0x0) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:418
#21 0x00007f82ea0ac1e6 in QObject::event(QEvent*) () from /usr/lib64/libQt5Core.so.5
#22 0x00007f82eab63a5f in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#23 0x00007f82ea080828 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#24 0x00007f82ea083eb5 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/libQt5Core.so.5
#25 0x00007f82ea0d30c3 in ?? () from /usr/lib64/libQt5Core.so.5
#26 0x00007f82e959a07b in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
#27 0x00007f82e959a338 in ?? () from /usr/lib64/libglib-2.0.so.0
#28 0x00007f82e959a3ef in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
#29 0x00007f82ea0d2b54 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/libQt5Core.so.5
#30 0x00007f82ea07f20b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/libQt5Core.so.5
#31 0x00007f82ea08786d in QCoreApplication::exec() () from /usr/lib64/libQt5Core.so.5
#32 0x00005631866c7924 in main (argc=1, argv=0x7ffff84fb408) at /home/w/src/libfive/studio/src/main.cpp:51

Versions

  • Operating system: Linux
  • libfive commit hash: 6f844b12
    • Is this the latest commit to master? yes
  • Qt version (if applicable): 5.15.5-r3
  • guile version: 3.0.8

Additional Information

  • I'm using guile 3.0.8 because libfive wouldn't compile under 2.0.14-r4.
  • I can only get this to crash with CMAKE_BUILD_TYPE=RelWithDbgInfo or Debug. Release isn't crashing for me.
  • I've not had great luck running the test suite:
desktop :: ~/src/libfive ‹master*› % ./build/libfive/test/libfive-test                                                                                                               

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libfive-test is a Catch v2.13.8 host application.
Run with -? for options

-------------------------------------------------------------------------------
Heightmap::render: 2D circle at non-zero Z 
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/heightmap.cpp:87
...............................................................................

/home/w/src/libfive/libfive/test/heightmap.cpp:108: FAILED:
  REQUIRE( (comp == out).all() )
with expansion:
  false
with message:
  out :=    -inf    -inf    -inf 1.00001 1.00001 1.00001 1.00001    -inf    -
  inf    -inf
     -inf 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001    -
  inf
     -inf 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001    -
  inf
  1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.
  00001
  1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.
  00001
  1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.
  00001
  1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.
  00001
     -inf 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001    -
  inf
     -inf 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001    -
  inf
     -inf    -inf    -inf 1.00001 1.00001 1.00001 1.00001    -inf    -inf    -
  inf

-------------------------------------------------------------------------------
Heightmap::render: Performance
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/heightmap.cpp:259
...............................................................................

benchmark name                       samples       iterations    estimated
                                     mean          low mean      high mean
                                     std dev       low std dev   high std dev
-------------------------------------------------------------------------------
sphere                                         100             1     2.80416 s 
                                        27.3713 ms    27.1748 ms    27.5737 ms 
                                        1.01141 ms    669.651 us     1.5392 ms 
                                                                               
Menger sponge                                  100             1     15.7603 s 
                                        153.405 ms    151.989 ms    155.129 ms 
                                        7.95899 ms    6.59856 ms    10.0415 ms 
                                                                               

-------------------------------------------------------------------------------
HybridMesher<3>: rotated cylinder meshing
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/hybrid_meshing.cpp:364
...............................................................................

/home/w/src/libfive/libfive/test/hybrid_meshing.cpp:386: FAILED:
  REQUIRE( t->leaf->vertex_on_surface[26] )
with expansion:
  false

-------------------------------------------------------------------------------
Mesh::render (face count in rectangular prism)
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/mesh.cpp:91
...............................................................................

/home/w/src/libfive/libfive/test/mesh.cpp:100: FAILED:
  REQUIRE( m->verts.size() == 9 )
with expansion:
  256 (0x100) == 9

-------------------------------------------------------------------------------
DCWorkerPool::build (progress callback)
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/progress.cpp:33
...............................................................................

/home/w/src/libfive/libfive/test/progress.cpp:71: warning:
  Callbacks not triggered (this is expected in debug builds)

/home/w/src/libfive/libfive/test/progress.cpp:71: warning:
  Callbacks not triggered (this is expected in debug builds)

/home/w/src/libfive/libfive/test/progress.cpp:71: warning:
  Callbacks not triggered (this is expected in debug builds)

-------------------------------------------------------------------------------
QEF::solve
  Fully constrained (1D line)
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/qef.cpp:62
...............................................................................

/home/w/src/libfive/libfive/test/qef.cpp:77: FAILED:
  REQUIRE( sol.error == Approx(0.0) )
with expansion:
  -0.0 == Approx( 0.0 )
with messages:
  sol.position := 2.00001
  sol.value := 4.0000000001

-------------------------------------------------------------------------------
SimplexTree<3>: Corner positions
  Single-cell sphere
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/simplex.cpp:139
...............................................................................

/home/w/src/libfive/libfive/test/simplex.cpp:160: FAILED:
  REQUIRE( t->leaf->sub[2].load()->vert == Eigen::RowVector3d( 0, -1, -1) )
with expansion:
  5.16192e-08          -1          -1
  ==
   0 -1 -1

-------------------------------------------------------------------------------
SimplexTree<3>: assignIndices with cell collapsing
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/simplex.cpp:322
...............................................................................

/home/w/src/libfive/libfive/test/simplex.cpp:349: FAILED:
  REQUIRE( (a.first - b.first).norm() < 1e-9 )
with expansion:
  0.3124999997 < 0.0000000011
with messages:
  a.first := -0.625
    1.25
   0.625
  b.first := -0.625
  0.9375
   0.625
  k.first.first->region.lower.transpose() := -0.625  0.625      0
  k.first.first->region.upper.transpose() :=     0  1.25 0.625
  (a.first - b.first).norm() := 0.3124999997

-------------------------------------------------------------------------------
Solver::findRoot
  Sum-of-squares performance
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/solver.cpp:85
...............................................................................

benchmark name                       samples       iterations    estimated
                                     mean          low mean      high mean
                                     std dev       low std dev   high std dev
-------------------------------------------------------------------------------
SOS root                                       100             1    19.5807 ms 
                                        192.226 us    181.677 us    204.282 us 
                                        57.5888 us    51.0611 us    62.4225 us 
                                                                               

-------------------------------------------------------------------------------
Tree::optimized
  (- -0.091 (/ (- z 2.7) 0.6))
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/tree.cpp:404
...............................................................................

/home/w/src/libfive/libfive/test/tree.cpp:409: FAILED:
  REQUIRE( ss.str() == "(- -0.091 (/ (- z 2.7) 0.6))" )
with expansion:
  "(- -0.0909999 (/ (- z 2.70001) 0.600001))"
  ==
  "(- -0.091 (/ (- z 2.7) 0.6))"

-------------------------------------------------------------------------------
Tree::apply
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/tree.cpp:747
...............................................................................

/home/w/src/libfive/libfive/test/tree.cpp:755: FAILED:
  REQUIRE( out.str() == "(/ (+ var-free 1.3) x)" )
with expansion:
  "(/ (+ var-free 1.30001) x)"
  ==
  "(/ (+ var-free 1.3) x)"

-------------------------------------------------------------------------------
Voxels::View::split
  With odd voxel count
-------------------------------------------------------------------------------
/home/w/src/libfive/libfive/test/voxels.cpp:167
...............................................................................

/home/w/src/libfive/libfive/test/voxels.cpp:189: FAILED:
  REQUIRE( a.upper.z() == 2 )
with expansion:
  2.00001f == 2

Error: wrong-type-arg (string-append Wrong type (expecting ~A): ~S (string #f) (#f)) /home/w/src/libfive
Error: misc-error (load-foreign-library file: ~S, message: ~S (libfive/src/libfive file not found) #f) /home/w/src/libfive
Error: wrong-type-arg (string-append Wrong type (expecting ~A): ~S (string #f) (#f)) /home/w/src/libfive
Error: misc-error (load-foreign-library file: ~S, message: ~S (libfive/stdlib/libfive-stdlib file not found) #f) /home/w/src/libfive
===============================================================================
test cases:    183 |    174 passed | 9 failed
assertions: 898553 | 898544 passed | 9 failed
@mkeeter mkeeter added the bug label Dec 2, 2022
@wridgers
Copy link
Contributor Author

wridgers commented Dec 4, 2022

So it turns out this is happening much more frequently for me, and with every build type.

I've done a bit of digging into a minimal examples where I type (cube [0 0 0] [1 1 1])<enter> into Studio and it crashes.

In setShapes, new_shapes and shapes both only contain 1 item. Those items have the same unique id.

>>> p *(new_shapes.begin())
$18 = (Studio::Shape *&) @0x555556e62120: 0x7fffe80e4be0
>>> p *(shapes.begin())
$19 = (Studio::Shape *&) @0x555556b3d7e0: 0x7fffe8036f70

>>> p (*new_shapes.begin())->getUniqueId(canonical)
$21 = (const void *) 0x555556ba60f0
>>> p (*shapes.begin())->getUniqueId(canonical)
$20 = (const void *) 0x555556ba60f0

But different ids of course

>>> p (*new_shapes.begin())->id()
$27 = (const void *) 0x7fffe80e5730
>>> p (*shapes.begin())->id()
$28 = (const void *) 0x7fffe803bec0

Given:
https://github.com/libfive/libfive/blob/master/studio/src/guile/interpreter.cpp#L326

I'm leaning towards guile version 3.0.8 is causing the problem here.

Maybe not, because Python crashes too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants