aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarvey Harrison <[email protected]>2014-08-06 07:36:42 -0700
committerHarvey Harrison <[email protected]>2014-08-06 07:36:42 -0700
commitfd0c674d66ce786a2c34495c7c9c12c11844b418 (patch)
tree31739cb50adb76781b7b075be838a115507d7049
parent4e09386403c7121ca95ad5a3497836223a73f76f (diff)
j3dcore: cannot lock an object using its own reference
When updating the orientTransforms array reference, you cannot lock the update using the same ref, as the next thread in will lock the new object and concurrently run with the original updater. Pointed out by findbugs. Signed-off-by: Harvey Harrison <[email protected]>
-rw-r--r--src/classes/share/javax/media/j3d/OrientedShape3DRetained.java33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/classes/share/javax/media/j3d/OrientedShape3DRetained.java b/src/classes/share/javax/media/j3d/OrientedShape3DRetained.java
index 5bdf87c..4fe4026 100644
--- a/src/classes/share/javax/media/j3d/OrientedShape3DRetained.java
+++ b/src/classes/share/javax/media/j3d/OrientedShape3DRetained.java
@@ -83,7 +83,8 @@ class OrientedShape3DRetained extends Shape3DRetained {
boolean orientedTransformDirty = true;
- Transform3D[] orientedTransforms = new Transform3D[1];
+ private final Object transformLock = new Object();
+ private Transform3D[] orientedTransforms = new Transform3D[1];
static final double EPSILON = 1.0e-6;
@@ -308,25 +309,21 @@ class OrientedShape3DRetained extends Shape3DRetained {
}
- Transform3D getOrientedTransform(int viewIndex) {
- synchronized(orientedTransforms) {
- if (viewIndex >= orientedTransforms.length) {
- Transform3D xform = new Transform3D();
- Transform3D[] newList = new Transform3D[viewIndex+1];
- for (int i = 0; i < orientedTransforms.length; i++) {
- newList[i] = orientedTransforms[i];
- }
- newList[viewIndex] = xform;
- orientedTransforms = newList;
- }
- else {
- if (orientedTransforms[viewIndex] == null) {
- orientedTransforms[viewIndex] = new Transform3D();
+ Transform3D getOrientedTransform(int viewIndex) {
+ synchronized (transformLock) {
+ // check if the transforms list needs to be expanded
+ if (viewIndex >= orientedTransforms.length) {
+ Transform3D[] newList = new Transform3D[viewIndex + 1];
+ System.arraycopy(orientedTransforms, 0, newList, 0, orientedTransforms.length);
+ orientedTransforms = newList;
+ }
+
+ if (orientedTransforms[viewIndex] == null)
+ orientedTransforms[viewIndex] = new Transform3D();
+
+ return orientedTransforms[viewIndex];
}
- }
}
- return orientedTransforms[viewIndex];
- }
// called on the parent object
// Should be synchronized so that the user thread does not modify the