0
votes

thanks for dropping over.

I got 2 issues with Box2DLights.

The first one isn't that important to solve, the second, however,

#1 : disposing lights

I got multiple PointLights that follow a porjectile. So every porjectile has an ArrayList with all the PointLights it needs in it. When the porjectile hits an object all the Lights should get disposed. Apparently that´s a problem.

if(hit){
      deleted = true;
      for(int i = 0; i<myLight.size();i++){
         myLight.get(i).dispose();
       }
}

This causes a Fatal Exeption

A fatal error has been detected by the Java Runtime Environment: EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffc6fc59f58, pid=6944, tid=6676 JRE version: Java(TM) SE Runtime Environment (8.0_45-b15) (build 1.8.0_45-b15) Java VM: Java HotSpot(TM) 64-Bit Server VM (25.45-b02 mixed mode windows-amd64 compressed oops) Problematic frame: C [ntdll.dll+0x39f58] Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

The problem, I guess, is that a disposed object somehow cant be referenced anymore by the ArrayList. The question is how to do this better.

#2 : ConeLight crashs my JavaTm (?)

When adding a ConeLight to my game

playerLight = new ConeLight(this,100,Color.WHITE,100,1920f/2f,1080f/2f,0,60);

//used "this" because I called this method in a class that extends RayHandler

my game just freezes in the Main Menu when pressing "Play" the MainMenu Screen just freezes and a little window appears that says:

"Java(TM) SE binary doesn't work anymore"

PointLight, howeever, works perfectly. I honestly have no clue and whether this is my fault or a bug.

2
Both of these errors are very low-level errors that are unlikely to be solved by changing lines of Java code. Please Google "EXCEPTION_ACCESS_VIOLATION LibGDX" and research the problem. It is likely a problem with your project set-up and dependencies.DavidS

2 Answers

2
votes

Answering to your question #1 - before disposing the light you should remove it from rayHandler. Otherwise, rayHandler will try to process disposed light and this seems to be the crash you are getting.

myLight.get(i).remove();

instead of

myLight.get(i).dispose();

Second point here is, possibly you shouldn't create and dispose the lights each time. For performance reasons (instantiation of light is quite heavy) you could better use the pooling. With pooling you could use the remove(false) (false prevents disposing it) and add() methods to do this.

Regarding the question #2 - I don't see any issue with ConeLight constructor params, also the tests with ConeLight doesn't reproduce your crash. Thus, possibly the problem might be in your extended class (or not). I suggest you to debug and locate the place of problem more preciesly.

0
votes

I have solved it, FINALLY. It was a pretty dumb mistake:

As I dont really need a World object, the RayHandler constructor, however, does, I created a World gave it the rayhandler and disposed it afterwards. Stupid, I know. So instead of

    public void create(){
       ....
       World world = new World(new Vector2(0,0),false);
       rayHandler = new RayHandler(world);
       world.dispose;
    }

You need to move world.dispose to the dispose method and make world a field.

public void create(){
       ....
       world = new World(new Vector2(0,0),false);
       rayHandler = new RayHandler(world);

    }
...
public void dispose(){
      ...
      rayHandler.dispose;
      world.dispose();
}