# LibGDX “EXCEPTION_ACCESS_VIOLATION” error when recreating previously disposed Box2DLights light

I just installed the Box2DLights dependency for LibGDX and I added a cave with 2 ConeLights inside. The first time I render the cave, everything works as expected. Then when I exit the cave, I make sure to dispose() all the lights. Then if I enter the cave again and try to create the same 2 ConeLights, it gives me this exception with a big error log (PasteBin added at the bottom of this post). If I don't dispose() the lights when exiting the cave, it won't crash the second time, but it will keep adding lights and it will get brighter and brighter and it's bad for performance. It doesn't matter if I use a PointLight or a ConeLight, the same exception will occur.

Everytime a map change occurs, destroyLighting() and then loadLighting() for the new map is called. The error happens when a ConeLight is created, the second time when you enter the cave (4th line in the loadLighting() method)

for(MapObject o : lightingObjects) {
EllipseMapObject circleMapObject = (EllipseMapObject) o;
Ellipse ellipse = circleMapObject.getEllipse();
Light light = new ConeLight(rayHandler, 60, new Color(255,225,166,1), 100, ellipse.x, ellipse.y, 90, 90);
light.setSoftnessLength(0);
}


destroyLighting():

for(Light light : lights) light.dispose();
lights.clear();


The error log: https://pastebin.com/1v36aNPg

Not really sure what causes the problem, but I think you should be disposing and recreating your RayHandler each time which internally takes care of disposing all the lights.