<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>1464</bug_id>
          
          <creation_ts>2023-09-26 14:15:12 +0200</creation_ts>
          <short_desc>GraphUI Scene: Resolve Data Race Modding Z Position activating a shape and Arrays.sort(..)</short_desc>
          <delta_ts>2024-02-07 15:30:52 +0100</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>GraphUI</product>
          <component>Core</component>
          <version>2.6.0</version>
          <rep_platform>All</rep_platform>
          <op_sys>all</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>critical</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>1454</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Sven Gothel">sgothel</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          
          
          <cf_type>DEFECT</cf_type>
          <cf_scm_refs>4b8574c63e100f0ef8bb2ad292d71f612e6cfceb</cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>6888</commentid>
    <comment_count>0</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2023-09-26 14:15:12 +0200</bug_when>
    <thetext>Currently the shape&apos;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 -&gt; Data race condition, inconsistency.

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

Exception in thread &quot;main-Display-.x11_:0-1-EDT-1&quot; 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 &quot;main-Display-.x11_:0-1-EDT-1&quot; 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)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6889</commentid>
    <comment_count>1</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2023-09-26 14:19:33 +0200</bug_when>
    <thetext>This bug became more visible since adding feature of Bug 1454</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>7118</commentid>
    <comment_count>2</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2024-02-07 15:30:52 +0100</bug_when>
    <thetext>commit 4b8574c63e100f0ef8bb2ad292d71f612e6cfceb

    Bug 1454 + Bug 1464: Maintain a Shape local &apos;zOffset&apos; 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).</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>