[BUG FIX] Mouse drag crashing the viewer in edge cases #644
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This change initializes the
_pdown
instance variable of theTrackball
object, which stores the x, y values of the initial mouse press for the camera drag in the viewer. It ensures_pdown
is initialized to zeroes instead ofNone
, preventing crashes in edge cases. Additionally, it removes the use ofgetattr
to access_pdown
, as it is always initialized.Related Issue
No related existing issue.
Motivation and Context
Previously, viewer would crash if the
on_mouse_drag
callback was triggered beforeon_mouse_click
. This happened because when the initial mouse press that should set_pdown
attribute was missing, it had original valueNone
from when theTrackball
instance is created, resulting in aTypeError
during camera drag calculations. This might happen in couple of edge cases, one way I am able to reliably reproduce it in my Ubuntu 24.04 system is listed below.Steps to reproduce
How Has This Been / Can This Be Tested?
Screenshots (if appropriate):
Screencast.from.2025-01-27.21-26-23.webm
Checklist:
Submitting Code Changes
section of CONTRIBUTING document.