libgdx / box2dlights

Fork of box2dlights by Kalle Hamalainen
Apache License 2.0
257 stars 82 forks source link

box2dLight.Light.dispose issue #92

Closed sebaber closed 8 years ago

sebaber commented 8 years ago

I have a problem when i want to removeAll from my RayHandler class, its something with the buffer. I dont know if its something with my code, or something with box2dlight class, thats the exception:

java.lang.IllegalArgumentException: buffer not allocated with newUnsafeByteBuffer or already disposed at com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(BufferUtils.java:507) at com.badlogic.gdx.graphics.glutils.VertexArray.dispose(VertexArray.java:65) at com.badlogic.gdx.graphics.Mesh.dispose(Mesh.java:507) at box2dLight.Light.dispose(Light.java:232) at box2dLight.RayHandler.removeAll(RayHandler.java:403)

I have that a RayHandler and i only set this things:

RayHandler rayHandler;

//I create and set some properties: rayHandler = new RayHandler(lightWorld); rayHandler.setBlur(false); rayHandler.setAmbientLight(new Color(1f,1f,1f,1f)); RayHandler.setGammaCorrection(true); RayHandler.useDiffuseLight(true);

// I removeAll in some cases: rayHandler.removeAll();

rinold commented 8 years ago

Sorry for late reply. This looks like (99%) the double call of dispose method for one light instance in your code.

Also, please post such questions on forum if you are unsure before doing it here - it's a bugtracker and not the help site :) P.S. Issue could be reopened if you are absolutely sure it's the box2dlights issue, not your code.

sebaber commented 8 years ago

Hi again. Sorry to dont be sure, but know i am. I see al the code for days to be sure and the only thing i do is that line of rayHandler:

// I removeAll in some cases: rayHandler.removeAll();

I think that the problem is like you say: "From some light disable, it dispose twice", but i see our code and dont see another dispose, only the removeAll from the rayHandler. So there is a way that the garbage collector dispose some PointLight but not remove from the list of light disable in the RayHandler? or there is a way that some PointLight can be save twice in the list of lights disable or active, or one instance of the same PointLight in both, of RayHandler?

We have a render method that has all the PoingLights in map disable, but the ones that are nearby the LocalPlayer set active, render, and after set disable again, and the other render the same. Is it okey?

I cant eliminate that problem, i read all issues similar but dont answer from my problem

rinold commented 8 years ago

This actually might happen if you are disabling/enabling lights and calling removeAll() in different threads. Is your issue stably reproduces in some scenarios or it occures rarely and randomly?

sebaber commented 8 years ago

rinold you save as man! thanks a lot, it was that, we have diferents threads working with disabling/enabling and dispose, we separete correctly and now works!!!

We love working with open source, and to see that we recognize that, take a look to our project:

http://littlewaronline.com/

Thanks again, and we allways be mention that lib part of libgdx!