Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: NevilleKemp

26. May 2012, 04:30:04 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)[FIXED] Probably threading glitch
Pages: [1]
Print
Author Topic: [FIXED] Probably threading glitch  (Read 334 times)
ChrisE
Becoming dependent
**
Offline Offline

Posts: 104


View Profile
« on: 24. January 2011, 10:23:50 pm »

Marvin,

This one is pretty straightforward.

The Bug
The bug was found calling RenderLoop.begin() and RenderLoop.end() repeatedly in response to a setVisible call. This is not right, I should've been using pauseRendering/resumeRendering, etc. etc.

That said, what happens the second time begin() is called is that it fails due to RenderLoop.getThread() returning non-null and the object deciding it doesn't need a "redundant" begin() call.


The Problem
After calling RenderLoop.end(), RenderLoop.super.end() (i.e., UpdatingThread.end()) is called, which sets isStopping to true, which kills the thread later in the UpdatingThread.loop() method. The containing method UpdatingThread.run() then sets UpdatingThread.thread to null.

In theory, this should set the derived RenderLoop.thread to null as well, thus allowing RenderLoop.begin() to be called multiple times.

However, on line 146 of RenderLoop.java we declare a private Thread variable, and so the expected behavior of using the superclass methods to control the thread does not work--specifically, we see that the thread from the superclass is set to null and so forth dutifully, but the allocated thread in RenderLoop is never touched when RenderLoop.end() is called.

And that is why you can't use RenderLoop.begin() and RenderLoop.end() back-to-back-to-back.

The Solution
I think you can just delete the private Thread member variable in RenderLoop, and defer to the super class's thread member variable.

EDIT: You'll have to go to line 301 of UpdatingThread.java and change the visibility of the thread member from 'private' to 'protected'.
« Last Edit: 25. January 2011, 11:42:57 pm by ChrisE » Logged
ChrisE
Becoming dependent
**
Offline Offline

Posts: 104


View Profile
« Reply #1 on: 25. January 2011, 03:50:53 pm »

Update! Patched it in my code, and it runs fine now. Cheesy

If anyone is interested, here's the patch:
Code:
Index: RenderLoop.java
===================================================================
--- RenderLoop.java (revision 1844)
+++ RenderLoop.java (working copy)
@@ -143,7 +143,7 @@
     private Xith3DEnvironment x3dEnv = null;
     
     private StopOperation stopOperation = null;
-    private Thread thread = null;
+    //private Thread thread = null;
     
     /**
      * @return the RunMode this RenderLoop is running in.
Index: UpdatingThread.java
===================================================================
--- UpdatingThread.java (revision 1844)
+++ UpdatingThread.java (working copy)
@@ -298,7 +298,8 @@
     private long iterations = -1L;
     private FPSLimiter fpsLimiter = new DefaultFPSLimiter();
     
-    private Thread thread = null;
+    protected Thread thread = null;
+   
     private boolean isStopping = false;
     
     private long minItTime;
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Online Online

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #2 on: 26. January 2011, 12:00:46 am »

Thanks. Good patch.
Logged
ChrisE
Becoming dependent
**
Offline Offline

Posts: 104


View Profile
« Reply #3 on: 26. January 2011, 03:15:49 pm »

Glad I could be of help!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic