ID 603282 - The kSelectionChanged event can trigger while Nuke Studio is in the process of closing, which can cause crashes

Follow

Problem summary:
The kSelectionChanged event can trigger while Nuke Studio is in the process of closing, which can cause crashes
 
Customer reported version:
Nuke Studio N/A
 
Customer reported platform:
N/A
 
Steps to reproduce:
1) Launch Nuke Studio and execute the following code in the Script Editor:

from hiero.core import events def on_selection_changed(event):     nuke.tprint("selection changed") events.registerInterest("kSelectionChanged/kTimeline", on_selection_changed)
2) Navigate to File > Import File(s)... and select some media to import
3) Drag and drop the media onto the Timeline
4) With Soft-Selection enabled, move the Playhead off of the Track Item, then back onto the Track Item 
5) Open the Terminal, and observe how two selection events occurred as expected:

6) Navigate to File > Quit (when prompted, you may chose to save or not save the project)
7) Open the Terminal, and observe how a third kSelectionChanged event has occurred during shutdown, despite the selection not changing:
 
 
Expected behavior:
kSelectionChanged events should only fire when the selection has changed.
 
Actual behavior:
When Nuke Studio is closed via File > Quit or the exit button, it is possible for kSelectionChanged events to activate. If the function(s) registered to the kSelectionChanged event make adjustments inside the Nuke Studio project file, Nuke Studio can then crash during the shutdown process.
For example, using the adjusted code below will cause a crash when repeating the above steps:
from hiero.core import events def on_selection_changed(event):     sequence = hiero.ui.activeSequence()     sequence.setInTime(5)     sequence.setOutTime(10)     nuke.tprint("selection changed") events.registerInterest("kSelectionChanged/kTimeline", on_selection_changed)
 
Workaround:
No known workaround at this time.
 
Reproduced by Support in:
Nuke Studio 16.0v4 - Windows 11, macOS 14 Sonoma
Nuke Studio 15.0v1 - Windows 11
Nuke Studio 14.0v1 - Windows 11
Nuke Studio 13.0v1 - Windows 11
Nuke Studio 12.0v1 - Windows 11
 
Earliest version tested:
Nuke Studio - This issue appears to be in all tested versions of the product

    We're sorry to hear that

    Please tell us why