Hi,
After I got 3D viewer sources, I have spent some time debugging my plugin. It hangs when I forward events between two universes, and so far I found the point where it hangs. To get you in context: The main class implements "UniverseListener" interface (thanks Johannes for pointing this out), which has three methods that I implement in the following way: public void transformationStarted(View view) { } public void transformationUpdated(View view) { synchronizeUniverses(view); } public void transformationFinished(View view) { synchronizeUniverses(view); } I register the listener for both universes: Image3DUniverse universe.addUniverseListener(this); So, whenever a transformation is made in one of them, the "synchronizeUniverses" method will be invoked: private void synchronizeUniverses(View view) { if (!dispatched) { dispatched = true; // Avoids infinite events forwarding if (view == universeVolume.getCanvas().getView()) { universeVolume.getGlobalTransform(gt); universeSphere.setGlobalTransform(gt); } else { universeSphere.getGlobalTransform(gt); universeVolume.setGlobalTransform(gt); } dispatched = false; // Reactivate events. } } Notice that the "dispatched" variable should avoid infinite events forwarding. Unluckily it doesn't work. There are two universes, so when events come from "universeVolume", it gets it's global transform to sets it at "universeSphere" and vice versa. When I drag one of the universes, it locks, but if I remove the "transformationUpdated", so only the transform will be updated when mouse is released, it works. Debugging inside 3D_Viewer sources I found that it hangs at "frameBehavior.wait()", where it stays locked forever. public void waitForNextFrame() { if (win == null) { return; } frameBehavior.postId(WaitForNextFrameBehavior.TRIGGER_ID); synchronized (frameBehavior) { try { frameBehavior.wait(); } catch (Exception e) { } } } I think it's a problem related to the "synchronized" part, because I tried to set the wait for 1 second and then infinite event forwarding appeared, but I can't manage how to fix that. Any help will be welcome, as this is the only remaining issue to finish my plugin :) Sincerelly, Juanjo Vega. |
Hi,
Finally I managed to fix my problem synchronizing universes in a different thread like: public void transformationUpdated(final View view) { // Synchronizes both universes in a different thread to avoid locks. new Thread(new Runnable() { public void run() { synchronizeUniverses(view); } }).start(); } Thanks anyway, Sincerelly, Juanjo Vega. On Fri, 2010-06-11 at 11:54 +0200, Juanjo Vega wrote: > Hi, > > After I got 3D viewer sources, I have spent some time debugging my > plugin. It hangs when I forward events between two universes, and so far > I found the point where it hangs. > > To get you in context: > > The main class implements "UniverseListener" interface (thanks Johannes > for pointing this out), which has three methods that I implement in the > following way: > > public void transformationStarted(View view) { > } > > public void transformationUpdated(View view) { > synchronizeUniverses(view); > } > > public void transformationFinished(View view) { > synchronizeUniverses(view); > } > > I register the listener for both universes: > > Image3DUniverse universe.addUniverseListener(this); > > So, whenever a transformation is made in one of them, the > "synchronizeUniverses" method will be invoked: > > > private void synchronizeUniverses(View view) { > if (!dispatched) { > dispatched = true; // Avoids infinite events forwarding > > if (view == universeVolume.getCanvas().getView()) { > universeVolume.getGlobalTransform(gt); > universeSphere.setGlobalTransform(gt); > } else { > universeSphere.getGlobalTransform(gt); > universeVolume.setGlobalTransform(gt); > } > > dispatched = false; // Reactivate events. > } > } > > Notice that the "dispatched" variable should avoid infinite events > forwarding. Unluckily it doesn't work. > > There are two universes, so when events come from "universeVolume", it > gets it's global transform to sets it at "universeSphere" and vice > versa. > > When I drag one of the universes, it locks, but if I remove the > "transformationUpdated", so only the transform will be updated when > mouse is released, it works. > > Debugging inside 3D_Viewer sources I found that it hangs at > "frameBehavior.wait()", where it stays locked forever. > > public void waitForNextFrame() { > if (win == null) { > return; > } > frameBehavior.postId(WaitForNextFrameBehavior.TRIGGER_ID); > synchronized (frameBehavior) { > try { > frameBehavior.wait(); > } catch (Exception e) { > } > } > } > > I think it's a problem related to the "synchronized" part, because I > tried to set the wait for 1 second and then infinite event forwarding > appeared, but I can't manage how to fix that. > > Any help will be welcome, as this is the only remaining issue to finish > my plugin :) > > Sincerelly, > > Juanjo Vega. |
Free forum by Nabble | Edit this page |