[FIXED] Problem with lights; No detach

Well, this topic will have no code here because there is none to put.

The problem is, when I attach a light to rootNode and then detach, it still stays there.

So when I switch between stages of game, the old lights don’t remove, just new come and at the end game gets so bright all you see is light color.

If you attach a light or detach it you have to use code. So there IS code.



Show that code and we’ll help you find the problem.

@madjack said:
If you attach a light or detach it you have to use code. So there IS code.

Show that code and we'll help you find the problem.

I mean, no relevant code. But here you go if you want it so much:
[java]rootNode.addLight(al);[/java]
and
[java]rootNode.removeLight(al);[/java]
or in some places
[java]app.getRootNode().addLight(al);[/java]
and
[java]app.getRootNode().removeLight(al);[/java]
app is instance of SimpleApplication (the real one that I use for everything)
and rootNode in first 2 lines is rootNode of app (the real one)

Try code with some context…like the method it’s in etc :wink:

@zarch said:
Try code with some context...like the method it's in etc ;)

Well it's in simpleInitApp, just did that to see does it remove light because I know that part of code runs and everything. Looks like the light still stays at same place. Try it yourself. Also removeLight is AFTER addLight, I'm not that stupid if you think so
@ivandonat said:
Try it yourself. Also removeLight is AFTER addLight, I'm not that stupid if you think so


All the lights in all my scenes are removed when I remove them. There's nothing to test. I work on Disenthral daily and I would see it if that was the case.

Post a simple test case for us to try. As hinted by others, if we do it ourselves then it will likely work just fine and that doesn’t really help anyone and kind of wastes our time a little.

2 Likes

Hmm now when I made a test case it works.

Does it matter if light is static and void where it is removed is static?

I will try making it non-static (Got a class Lights.java that has all static) and

will inform you on my progress.



EDIT:

Hmm, I got this

[java] @Override

public void cleanup() {

super.cleanup();



chaseCam.setEnabled(false);

app.getFlyByCamera().setEnabled(true);



gui.setEnabled(false);

app.lockMouse();

app.getRootNode().detachAllChildren();

app.getStateManager().detach(bullet);

}[/java]

When I detach this state, shouldn’t it remove the lights?

Because it doesn’t :open_mouth:

Of course that won’t work.



You’ve got to remove the lights using:



node.removeLight(someLight);



node.detachAllChildren(); does NOT remove lights.

1 Like
@madjack said:
Of course that won't work.

You've got to remove the lights using:

node.removeLight(someLight);

node.detachAllChildren(); does NOT remove lights.

To remove all lights, can I do getLights() or something like that and then make a for loop that removes each of those?

Something like getLocalLightList() for example?



In fact getLocalLightList().clear() might do what you want although I’ve not tried it…

@ivandonat said:
To remove all lights, can I do getLights() or something like that and then make a for loop that removes each of those?


Yes. There's a method in Node called getLocalLightList(). Just do a for each loop and use node.removeLight(loopLight).

Like this. (From memory, check the method names to be sure):
[java]
for (Light light : node.getLocalLightList()) {
node.removeLight(light);
}
[/java]

That should work.
1 Like
@madjack said:
Yes. There's a method in Node called getLocalLightList(). Just do a for each loop and use node.removeLight(loopLight).

Like this. (From memory, check the method names to be sure):
[java]
for (Light light : node.getLocalLightList()) {
node.removeLight(light);
}
[/java]

That should work.

Okay got a few ideas how lights work.
Is there a way to close the thread?
Also thanks guys :)
@ivandonat said:
Okay got a few ideas how lights work.
Is there a way to close the thread?
Also thanks guys :)


No thread closing, but you can edit your topic with [FIXED] as this might help others with similar issues. Also, thumbing up is appreciated. ;)
1 Like
@ivandonat said:
Hmm now when I made a test case it works.


P.S.: This is one of the main reasons we ask for a test case. The other being that if you had actually found a bug in the engine then we'd have a ready made test case for fixing it. Mostly the first one, though. :)