Skip to content

Commit 4933949

Browse files
committed
Uniform: fix crash when using vector4array
1 parent e6d829f commit 4933949

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

jme3-core/src/main/java/com/jme3/shader/Uniform.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -332,30 +332,29 @@ public void setValue(VarType type, Object value){
332332
}
333333

334334
public void setVector4Length(int length){
335-
if (location == -1)
335+
if (location == -1) {
336336
return;
337-
338-
FloatBuffer fb = (FloatBuffer) value;
339-
if (fb == null || fb.capacity() < length * 4) {
340-
value = BufferUtils.createFloatBuffer(length * 4);
341337
}
342-
338+
339+
multiData = BufferUtils.ensureLargeEnough(multiData, length * 4);
340+
value = multiData;
343341
varType = VarType.Vector4Array;
344342
updateNeeded = true;
345343
setByCurrentMaterial = true;
346344
}
347345

348346
public void setVector4InArray(float x, float y, float z, float w, int index){
349-
if (location == -1)
347+
if (location == -1) {
350348
return;
349+
}
351350

352-
if (varType != null && varType != VarType.Vector4Array)
353-
throw new IllegalArgumentException("Expected a "+varType.name()+" value!");
351+
if (varType != null && varType != VarType.Vector4Array) {
352+
throw new IllegalArgumentException("Expected a " + varType.name() + " value!");
353+
}
354354

355-
FloatBuffer fb = (FloatBuffer) value;
356-
fb.position(index * 4);
357-
fb.put(x).put(y).put(z).put(w);
358-
fb.rewind();
355+
multiData.position(index * 4);
356+
multiData.put(x).put(y).put(z).put(w);
357+
multiData.rewind();
359358
updateNeeded = true;
360359
setByCurrentMaterial = true;
361360
}

0 commit comments

Comments
 (0)