libgdx / box2dlights

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

Lights are duplicated, triplicated, etc #102

Closed chelinho139 closed 7 years ago

chelinho139 commented 7 years ago

Hello, I have a big problem.

I have a main menu screen and a game screen.

The menu screen has no lights. The game screen is the only one that has lights.

Every time I go from the game screen to the menu screen and back to the game, the lights are duplicated.

Example: Main Menu -> Game (ok) Main Menu -> Game -> Main Menu -> Game (all lights get duplicated)

I know it may sound stupid, but no, i am properly disposing everything. Even I checked with the debugger and breakpoint the rayhandler class, it has the correct number of lights (in the array: lights) but still all the lights get duplicated.

I will show you my code:

Init:

`

    lightWorld = new World(new Vector2(0, 0), true);

    rayHandler = new RayHandler(lightWorld);

    rayHandler.setBlur(false);

    rayHandler.setAmbientLight(new Color(1f,1f,1f,1f));

    RayHandler.setGammaCorrection(true);

    RayHandler.useDiffuseLight(true);`

and dispose:

`

        rayHandler.getLightMapBuffer().dispose();

        rayHandler.dispose();

        lightWorld.dispose();`

I cant figure out how to solve it. and every time the lights start to duplicate, triplicate, and so on. its horrible!

Please help me!

chelinho139 commented 7 years ago

Update:

I solve by removing this line: RayHandler.setGammaCorrection(true);

rinold commented 7 years ago

Very odd, cause this method doesn't affect the lights count. Btw, some of static methods of ray handler, must be called before instance creation, so - that one should be called before you are instantiating the RayHandler:

RayHandler.setGammaCorrection(true);

It affects the shaders loading, and setting it to true after the shader is loaded with gamma correction set to false, might lead to issues. Could you please try to set them before creating the ray handler, and check if issues still occurs?

Also, the following line is not needed, as it will be called by rayHandler.dispose() internally:

rayHandler.getLightMapBuffer().dispose();