Skip to content

Commit f0417dc

Browse files
authored
[BUG FIX] Mouse drag crashing the viewer in edge cases (#644)
* fix: crash in viewer when dragging camera before initial click Previously, viewer would crash if the `on_mouse_drag` callback was triggered before `on_mouse_click`. This happened because the initial mouse press would set `_pdown` attribute, which was initialized to `None` when the `Trackball` instance is created, resulting in a `TypeError` during camera drag calculations. This fix ensures the `_pdown` value is properly initialized to prevent the crash in some edge cases like window snap resizing. It also removes the attribute access to `_pdown` with getattr since it is always initialized. * chore: fix typo in comment
1 parent 7e0adc0 commit f0417dc

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

genesis/ext/pyrender/trackball.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, pose, size, scale, target=np.array([0.0, 0.0, 0.0])):
4646

4747
self._state = Trackball.STATE_ROTATE
4848

49-
self._pdown = None # Initialize _pdown attribute to None
49+
self._pdown = np.array([0.0, 0.0], dtype=np.float32)
5050

5151
@property
5252
def pose(self):
@@ -88,7 +88,7 @@ def down(self, point):
8888
self._target = self._n_target
8989

9090
def drag(self, point):
91-
"""Update the tracball during a drag.
91+
"""Update the trackball during a drag.
9292
9393
Parameters
9494
----------
@@ -98,9 +98,7 @@ def drag(self, point):
9898
motion between this point and the one marked by down().
9999
"""
100100
point = np.array(point, dtype=np.float32)
101-
# get the "down" point defaulting to current point making
102-
# this a no-op if the "down" event didn't trigger for some reason
103-
dx, dy = point - getattr(self, "_pdown", point)
101+
dx, dy = point - self._pdown
104102
mindim = 0.3 * np.min(self._size)
105103

106104
target = self._target

0 commit comments

Comments
 (0)