Hello all,
due to this JVM bug: http://bugs.sun.com/view_bug.do?bug_id=4469299 I’m facing a number of java.lang.OutOfMemoryError in my shader code, coming from LWJGLShaderUtil.updateUniformLocation();
So I decided to minimize byteBuffer creation by simply referring to a shared byteBuffer allocated statically.
Here’s the patch for LWJGLShaderUtil. It works very well and now the application does not crash anymore for OutOfMemoryError.
Index: LWJGLShaderUtil.java
===================================================================
--- LWJGLShaderUtil.java (revision 5353)
+++ LWJGLShaderUtil.java (working copy)
@@ -62,6 +62,8 @@
/** Utility class for updating shadervariables(uniforms and attributes) */
public class LWJGLShaderUtil {
private static final Logger logger = Logger.getLogger(LWJGLShaderUtil.class.getName());
+
+ private static ByteBuffer nameBuf = BufferUtils.createByteBuffer(2048);
/**
* Updates a uniform shadervariable.
@@ -107,10 +109,10 @@
public static void updateUniformLocation(ShaderVariable variable,
int programID) {
if (variable.variableID == -1) {
- ByteBuffer nameBuf = BufferUtils
- .createByteBuffer(variable.name.getBytes().length + 1);
+
nameBuf.clear();
nameBuf.put(variable.name.getBytes());
+ nameBuf.put((byte)0);
nameBuf.rewind();
variable.variableID = ARBShaderObjects
@@ -207,10 +209,10 @@
public static void updateAttributeLocation(ShaderVariable variable,
int programID) {
if (variable.variableID == -1) {
- ByteBuffer nameBuf = BufferUtils
- .createByteBuffer(variable.name.getBytes().length + 1);
+
nameBuf.clear();
nameBuf.put(variable.name.getBytes());
+ nameBuf.put((byte)0);
nameBuf.rewind();
variable.variableID = ARBVertexShader