[Nifty] markForRemoval() and hidden panel. Bug ? --Corrected

Hi !

It’s still me. Sorry for this surge of posts.

This one is more like a bug report like a real question. ( If the tests have done are correct )



I’ve created a simple Callable class for cleaning the content of a panel :

[java]

public class PanelCleaner implements Callable<Object> {



private Screen screen;

private Element parent;



public PanelCleaner( Screen screen, Element parent )

{

this.screen = screen;

this.parent = parent;

}





@Override

public Object call() throws Exception

{

if( ! screen.isRunning() )

return null;



for( Iterator<Element> i = parent.getElements().iterator(); i.hasNext(); )

{

Element element = i.next();

element.markForRemoval();

}

return null;

}

}

[/java]

And I call it like that :

[java]

application.enqueue( new PanelCleaner( screen, panel ) );

[/java]



This method works fine … for most of the cases.

This morning I tried to use it when the panel was hidden … and it doesn’t work :frowning:



For my case, I just had to make the panel visible before removing the element, but it may become anoying for more complex GUIs



PS : I checked the tracker but didn’t see anything related to that. So I will let void256 decide if it’s a real bug or not :slight_smile:

Just commited the bugfix to SVN:



@public

Bugfix: calling element.markForRemoval() on hidden elements did not remove the element at all. Cause: markForRemoval() will call the onEndScreen() effect for the element being removed. However, if the element is not visible the onEndScreen() effect was never started (it doesn’t make sense to start this effect for hidden elements) which never called the EndNotify() of this effect and therefore the element was never really removed. This is fixed now, you should be able to remove hidden elements too.



Thanks for pointing it out!

Perfect !



Thanks for correcting it !