aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgor Tsinko <[email protected]>2020-02-20 11:22:51 -0700
committerEgor Tsinko <[email protected]>2020-02-20 11:22:51 -0700
commit4cd3f974671214ac436f781991300db2b4c6378b (patch)
tree54b87d929b72a1f13b7e2747e1373bd1659bf898
parentc9efc71a7d983d8753ca34ad7fce5022924d1a5c (diff)
Fixed an issue with shared readRasterReady variable in GraphicsContext3D
-rw-r--r--src/main/java/org/jogamp/java3d/GraphicsContext3D.java36
-rw-r--r--src/main/java/org/jogamp/java3d/Renderer.java3
2 files changed, 18 insertions, 21 deletions
diff --git a/src/main/java/org/jogamp/java3d/GraphicsContext3D.java b/src/main/java/org/jogamp/java3d/GraphicsContext3D.java
index 6844b95..ed23fd5 100644
--- a/src/main/java/org/jogamp/java3d/GraphicsContext3D.java
+++ b/src/main/java/org/jogamp/java3d/GraphicsContext3D.java
@@ -30,6 +30,7 @@ import java.awt.Dimension;
import java.awt.Point;
import java.util.Iterator;
import java.util.Vector;
+import java.util.concurrent.CountDownLatch;
import org.jogamp.vecmath.Color3f;
import org.jogamp.vecmath.Vector3d;
@@ -314,9 +315,6 @@ public class GraphicsContext3D extends Object {
private int numActiveTexUnit = 0;
private int lastActiveTexUnitIndex = 0;
- // for read raster
- private volatile boolean readRasterReady = false;
-
// for runMonitor
private boolean gcReady = false;
private int waiting = 0;
@@ -2230,27 +2228,21 @@ public int numSounds() {
(!canvas3d.view.active)) {
return;
} else if (Thread.currentThread() == canvas3d.screen.renderer) {
- doReadRaster(raster);
- } else if (Thread.currentThread() ==
- canvas3d.view.universe.behaviorScheduler) {
- readRasterReady = false;
- sendRenderMessage(false, GraphicsContext3D.READ_RASTER, raster, null);
- while (!readRasterReady) {
- MasterControl.threadYield();
- }
+ doReadRaster(raster, null);
} else {
- // call from user thread
- readRasterReady = false;
- sendRenderMessage(true, GraphicsContext3D.READ_RASTER, raster, null);
- while (!readRasterReady) {
- MasterControl.threadYield();
- }
+ CountDownLatch latch = new CountDownLatch(1);
+ sendRenderMessage(Thread.currentThread() != canvas3d.view.universe.behaviorScheduler,
+ GraphicsContext3D.READ_RASTER, raster, latch);
+ try {
+ latch.await();
+ } catch (InterruptedException ignored) {
+ }
}
}
- void doReadRaster(Raster raster) {
+ void doReadRaster(Raster raster, CountDownLatch latch) {
+ try {
if (!canvas3d.firstPaintCalled) {
- readRasterReady = true;
return;
}
@@ -2374,7 +2366,11 @@ public int numSounds() {
((DepthComponentNativeRetained)ras.depthComponent).retrieveDepth(
intBuffer, rasterSize.width, rasterSize.height);
}
- readRasterReady = true;
+ } finally {
+ if (latch != null) {
+ latch.countDown();
+ }
+ }
}
/**
diff --git a/src/main/java/org/jogamp/java3d/Renderer.java b/src/main/java/org/jogamp/java3d/Renderer.java
index 01958e3..3e5a384 100644
--- a/src/main/java/org/jogamp/java3d/Renderer.java
+++ b/src/main/java/org/jogamp/java3d/Renderer.java
@@ -39,6 +39,7 @@ import java.awt.image.ImageObserver;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
+import java.util.concurrent.CountDownLatch;
import java.util.logging.Level;
@@ -691,7 +692,7 @@ ArrayList<TextureRetained> textureIDResourceTable = new ArrayList<TextureRetaine
break;
case GraphicsContext3D.READ_RASTER:
canvas.graphicsContext3D.doReadRaster(
- (Raster)m[nmesg].args[2]);
+ (Raster)m[nmesg].args[2], (CountDownLatch) m[nmesg].args[3]);
break;
case GraphicsContext3D.SET_APPEARANCE:
canvas.graphicsContext3D.doSetAppearance(