Note that there are some explanatory texts on larger screens.

plurals
  1. POArray of Objects to be used as Synchronization locks being garbage collected
    primarykey
    data
    text
    <p>Hopefully I'm just making a newbie mistake and someone can point me in the right direction, but here goes:</p> <p>I need to create a collect or array, some sort of organized group of Objects (or anything else that works) to use as synchronization locks for rendering methods. I have been storing an Object[] as a field, and it seems not to like to store data. Oddly enough, I don't have a problem when I set the lock objects as fields in my class, however if I try to use an array like below, they will return null on lock checks.</p> <p>First I initialize my lock array:</p> <pre><code>for(int i=0; i&lt;limit*limit; i++) { vertexbufferlocks[i]=new Object();} </code></pre> <p>Then I call my rendering function: </p> <pre><code>for(int buf=0; buf&lt;limit*limit; buf++){ synchronized(bmem.vertexbufferlocks[buf]){ bindbuffer(vbids[buf]); GL11.glDrawArrays(GL11.GL_QUADS, 0, drawlengths[buf]); }} </code></pre> <p>Which throws: <code>NullPointerException on bmem.vertexbufferlocks[buf]</code> on the line <code>synchronized(bmem.vertexbufferlocks[buf]){</code> I am definately running the constructor loop first. I tried using a LinkedList, List, and HashMap too, same problem. I am only having problems using this particular type, I have other synchronized classes used for data, initialized and read at the same times, which are not being affected.</p> <p>New Details:</p> <p><strong>THIS</strong> model works fine for me, but causes very small visual hitches since I can't render any data while any other data is being modified, all calls are in the same position as before:</p> <p>Init:</p> <pre><code> vertexbufferlock=new Object(); </code></pre> <p>Much later after the whole program is initialized:</p> <pre><code>for(int buf=0; buf&lt;limit*limit; buf++){ synchronized(bmem.vertexbufferlock){ bindbuffer(vbids[buf]); GL11.glDrawArrays(GL11.GL_QUADS, 0, drawlengths[buf]); }} </code></pre> <p>I think the key problem to address here is that my Objects are probably being garbage collected out of my array once the loop finishes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload