Bug 1464 - GraphUI Scene: Resolve Data Race Modding Z Position activating a shape and Arrays.sort(..)
Summary: GraphUI Scene: Resolve Data Race Modding Z Position activating a shape and Ar...
Status: RESOLVED FIXED
Alias: None
Product: GraphUI
Classification: JogAmp
Component: Core (show other bugs)
Version: 2.6.0
Hardware: All all
: P2 critical
Assignee: Sven Gothel
URL:
Depends on: 1454
Blocks:
  Show dependency treegraph
 
Reported: 2023-09-26 14:15 CEST by Sven Gothel
Modified: 2024-02-07 15:30 CET (History)
0 users

See Also:
Type: DEFECT
SCM Refs:
4b8574c63e100f0ef8bb2ad292d71f612e6cfceb
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Gothel 2023-09-26 14:15:12 CEST
Currently the shape's Z Position is modified within the mouse event dispatcher (Input EDT/thread) as well as read on same thread and on a renderer thread using Arrays.sort(..). 
The position might also been modified on another thread than the Input EDT/thread, e.g. the renderer thread -> Data race condition, inconsistency.

Arrays.sort(..) using TimSort detects the data race sometimes, i.e. throws an exception since the equals methods doesn't match anymore:

Exception in thread "main-Display-.x11_:0-1-EDT-1" java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at java.base/java.util.TimSort.mergeHi(TimSort.java:903)
        at java.base/java.util.TimSort.mergeAt(TimSort.java:520)
        at java.base/java.util.TimSort.mergeForceCollapse(TimSort.java:461)
        at java.base/java.util.TimSort.sort(TimSort.java:254)
        at java.base/java.util.Arrays.sort(Arrays.java:1233)
        at jogamp.graph.ui.TreeTool.forSortedAll(TreeTool.java:132)
        at com.jogamp.graph.ui.Group.forSortedAll(Group.java:369)
        at jogamp.graph.ui.TreeTool.forSortedAll(TreeTool.java:141)
        at com.jogamp.graph.ui.Scene.forSortedAll(Scene.java:739)
        at com.jogamp.graph.ui.Scene.pickShape(Scene.java:563)
        at com.jogamp.graph.ui.Scene.dispatchMouseEventPickShape(Scene.java:996)
        at com.jogamp.graph.ui.Scene$SBCMouseListener.mouseMoved(Scene.java:1096)
        at jogamp.newt.WindowImpl.dispatchMouseEvent(WindowImpl.java:4498)
        at jogamp.newt.WindowImpl.consumePointerEvent(WindowImpl.java:4346)
        at jogamp.newt.WindowImpl.consumeEvent(WindowImpl.java:3744)
        at jogamp.newt.WindowImpl.doEvent(WindowImpl.java:3686)
        at jogamp.newt.WindowImpl.doPointerEvent(WindowImpl.java:4131)
        at jogamp.newt.WindowImpl.doMouseEvent(WindowImpl.java:3794)
        at jogamp.newt.driver.x11.WindowDriver.doMouseEvent(WindowDriver.java:489)
        at jogamp.newt.WindowImpl.sendMouseEvent(WindowImpl.java:3761)
        at jogamp.newt.driver.x11.DisplayDriver.DispatchMessages0(Native Method)
        at jogamp.newt.driver.x11.DisplayDriver.dispatchMessagesNative(DisplayDriver.java:112)
        at jogamp.newt.DisplayImpl.dispatchMessages(DisplayImpl.java:753)
        at jogamp.newt.DisplayImpl$7.run(DisplayImpl.java:672)
        at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:347)
Exception in thread "main-Display-.x11_:0-1-EDT-1" java.lang.RuntimeException: X11Display.DispatchMessages0: MotionNotify: Exception occured at sendMouseEvent(..)
        at jogamp.newt.driver.x11.DisplayDriver.DispatchMessages0(Native Method)
        at jogamp.newt.driver.x11.DisplayDriver.dispatchMessagesNative(DisplayDriver.java:112)
        at jogamp.newt.DisplayImpl.dispatchMessages(DisplayImpl.java:753)
        at jogamp.newt.DisplayImpl$7.run(DisplayImpl.java:672)
Comment 1 Sven Gothel 2023-09-26 14:19:33 CEST
This bug became more visible since adding feature of Bug 1454
Comment 2 Sven Gothel 2024-02-07 15:30:52 CET
commit 4b8574c63e100f0ef8bb2ad292d71f612e6cfceb

    Bug 1454 + Bug 1464: Maintain a Shape local 'zOffset' and only consider it for sorting w/o actually modifying the position (enogh to be painted on top and for selection)
    
    Also use a simplified comparison using only float relational operations w/o NaN/Inf bit-stuff or epsilon,
    as it should be accurate enough for this cause.
    
    This shall also resolve Bug 1454, as we no more modify the position directly
    but the local zOffset field .. but this has to be seen (data race).