- fixed worldPlane init to avoid NPE when camera is loaded from a saved file.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7504 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent ab10b457b0
commit bc8162104f
  1. 19
      engine/src/core/com/jme3/renderer/Camera.java

@ -210,12 +210,15 @@ public class Camera implements Savable, Cloneable {
/** The camera's name. */ /** The camera's name. */
protected String name; protected String name;
/** /**
* Don't use this constructor, use Camera(int width, int height) * Don't use this constructor, use Camera(int width, int height)
* This constructor is for serialization only * This constructor is for serialization only
*/ */
public Camera(){ public Camera() {
worldPlane = new Plane[MAX_WORLD_PLANES];
for (int i = 0; i < MAX_WORLD_PLANES; i++) {
worldPlane[i] = new Plane();
}
} }
/** /**
@ -223,6 +226,7 @@ public class Camera implements Savable, Cloneable {
* values of the camera are set to default. * values of the camera are set to default.
*/ */
public Camera(int width, int height) { public Camera(int width, int height) {
this();
location = new Vector3f(); location = new Vector3f();
rotation = new Quaternion(); rotation = new Quaternion();
@ -243,11 +247,6 @@ public class Camera implements Savable, Cloneable {
viewPortTop = 1.0f; viewPortTop = 1.0f;
viewPortBottom = 0.0f; viewPortBottom = 0.0f;
worldPlane = new Plane[MAX_WORLD_PLANES];
for (int i = 0; i < MAX_WORLD_PLANES; i++) {
worldPlane[i] = new Plane();
}
this.width = width; this.width = width;
this.height = height; this.height = height;
@ -1363,7 +1362,7 @@ public class Camera implements Savable, Cloneable {
public void read(JmeImporter e) throws IOException { public void read(JmeImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this); InputCapsule capsule = e.getCapsule(this);
location = (Vector3f) capsule.readSavable("location", Vector3f.ZERO.clone()); location = (Vector3f) capsule.readSavable("location", Vector3f.ZERO.clone());
rotation = (Quaternion) capsule.readSavable("rotation", Quaternion.DIRECTION_Z); rotation = (Quaternion) capsule.readSavable("rotation", Quaternion.DIRECTION_Z.clone());
frustumNear = capsule.readFloat("frustumNear", 1); frustumNear = capsule.readFloat("frustumNear", 1);
frustumFar = capsule.readFloat("frustumFar", 2); frustumFar = capsule.readFloat("frustumFar", 2);
frustumLeft = capsule.readFloat("frustumLeft", -0.5f); frustumLeft = capsule.readFloat("frustumLeft", -0.5f);
@ -1378,8 +1377,8 @@ public class Camera implements Savable, Cloneable {
viewPortRight = capsule.readFloat("viewPortRight", 1); viewPortRight = capsule.readFloat("viewPortRight", 1);
viewPortTop = capsule.readFloat("viewPortTop", 1); viewPortTop = capsule.readFloat("viewPortTop", 1);
viewPortBottom = capsule.readFloat("viewPortBottom", 0); viewPortBottom = capsule.readFloat("viewPortBottom", 0);
width = capsule.readInt("width", 0); width = capsule.readInt("width", 1);
height = capsule.readInt("height", 0); height = capsule.readInt("height", 1);
name = capsule.readString("name", null); name = capsule.readString("name", null);
onFrustumChange(); onFrustumChange();
onViewPortChange(); onViewPortChange();

Loading…
Cancel
Save