From 49339497fa3ab6fd3ba51cf81dc1f40d72a45e62 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sat, 5 Sep 2015 17:31:59 -0400 Subject: [PATCH] Uniform: fix crash when using vector4array --- .../main/java/com/jme3/shader/Uniform.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/shader/Uniform.java b/jme3-core/src/main/java/com/jme3/shader/Uniform.java index 521b10d38..9580d8b72 100644 --- a/jme3-core/src/main/java/com/jme3/shader/Uniform.java +++ b/jme3-core/src/main/java/com/jme3/shader/Uniform.java @@ -332,30 +332,29 @@ public class Uniform extends ShaderVariable { } public void setVector4Length(int length){ - if (location == -1) + if (location == -1) { return; - - FloatBuffer fb = (FloatBuffer) value; - if (fb == null || fb.capacity() < length * 4) { - value = BufferUtils.createFloatBuffer(length * 4); } - + + multiData = BufferUtils.ensureLargeEnough(multiData, length * 4); + value = multiData; varType = VarType.Vector4Array; updateNeeded = true; setByCurrentMaterial = true; } public void setVector4InArray(float x, float y, float z, float w, int index){ - if (location == -1) + if (location == -1) { return; + } - if (varType != null && varType != VarType.Vector4Array) - throw new IllegalArgumentException("Expected a "+varType.name()+" value!"); + if (varType != null && varType != VarType.Vector4Array) { + throw new IllegalArgumentException("Expected a " + varType.name() + " value!"); + } - FloatBuffer fb = (FloatBuffer) value; - fb.position(index * 4); - fb.put(x).put(y).put(z).put(w); - fb.rewind(); + multiData.position(index * 4); + multiData.put(x).put(y).put(z).put(w); + multiData.rewind(); updateNeeded = true; setByCurrentMaterial = true; }