Permalink
Browse files

Fix a bug where removing a Layer's last listener broke child layers' …

…listeners.

When you add a listener, a Layer makes itself and its ancestors
interactive. But when you remove the last listener on a Layer, it would mark
itself non-interactive. Everything's happy until you have:

LayerA contains LayerB
Add listener to LayerB
Add listener to LayerA, disconnect LayerA's listener.

Now, LayerA would mark itself non-interactive even though it was for the
sake of LayerB, so you'd get the symptom of LayerB's listener going awol
(until you happened to add another listener somewhere at or under LayerA,
and it would spring back to life)

GroupLayerImpl.hitTest() already takes care of lazily noticing that an
otherwise listener-free Layer no longer has any interactive children,
so let's have that handle it for this case, as well.
  • Loading branch information...
1 parent c59a70f commit b555a8f635db6b5f4e893e04203702ff2e954fd8 @deadmoose deadmoose committed Jan 10, 2013
Showing with 4 additions and 2 deletions.
  1. +4 −2 core/src/playn/core/AbstractLayer.java
@@ -383,8 +383,10 @@ boolean hasInteractors() {
return new Connection() {
public void disconnect() {
rootInteractor = removeInteractor(rootInteractor, newint);
- // if we have no more interactors, become non-interactive
- if (rootInteractor == null)
+ // if we have no more interactors, become non-interactive. But not if we're a
+ // GroupLayer; we may be interactive for the sake of our children. In that case,
+ // we'll lazily realize and deal with it later
+ if (rootInteractor == null && !(AbstractLayer.this instanceof GroupLayer))
setInteractive(false);
}
};

0 comments on commit b555a8f

Please sign in to comment.