Mediator destroyed right after being initialized

H3LL3Ktro's Avatar

H3LL3Ktro

27 Jun, 2013 11:13 AM

Hi!

I´m having a really weird error that I cannot manage to solve and I need some help.
I´m initializing the context in the main of the application and adding it as a Sprite

questRobotlegs = new CareerQuestContext();
questUIComponent = new UIComponent();
questUIComponent.addChild(questRobotlegs as Sprite);
popupCanvas.addChildAt(questUIComponent,0);

When the configuration has finished setting up the system the View is created correctly and the Mediator (which is mapped to it through the configuration) is also created.

The problem is that the Mediator gets destroyed right after being initialized and in the stack I can see that "onRemovedFromStage" is called from robotlegs. The view by the way is still there, because I can press the buttons and dispatch the events but obviously (because there is no Mediator) the events are not caught and the command does not trigger.

Furthermore,
if in the mediator I use view.addEventListener(CareerEvent.OPEN_POPUP,passEvent); instead of addViewListener than robotlegs tries to destroy it but it fails.
As result the mediator is still there and the command get triggered correctly.

The mediator should not be removed by robotlegs after being created, so maybe there is something I am missing... But I do not know what

  1. Support Staff 1 Posted by Ondina D.F. on 27 Jun, 2013 02:07 PM

    Ondina D.F.'s Avatar

    Hello,

    The problem is that the Mediator gets destroyed right after being initialized and in the stack I can see that "onRemovedFromStage" is called from robotlegs

    My first thought is that there might be some re-parenting issues – the view being added to another container right after it has been added to the stage.
    I couldn’t make your app work, because of the missing classes. I took a look at the code, but I can’t see what’s wrong. Perhaps I’m just blind today ;)

    questRobotlegs = new CareerQuestContext(); questUIComponent = new UIComponent();
    questUIComponent.addChild(questRobotlegs as Sprite);
    popupCanvas.addChildAt(questUIComponent,0);

    Now, the above snippet is not included in your code, but it looks like a re-parenting issue after all. When questRobotlegs is added to your questUIComponent, your AnchorBarView gets re-parented, after it was added to questRobotlegs.

    If that’s not the issue, I suggest trying to add a simple view instead of your AnchorBarView, not extending anything and not using a factory or alike, to see what happens.

    I see you use an older version of rl2.
    If you decide to use the rl2 release build you’ll need to do it like so:
    _context.afterInitializing(initAnchorBar);

    Just for your information: if autoRemove is set to false, the mediator won’t be removed automatically. Of course, you’ll have to remove it yourself, if need be.

    mediatorMap.map(SomeView).toMediator(SomeMediator).autoRemove(false);

    I don’t know if that solves your problem though.

  2. Support Staff 2 Posted by Ondina D.F. on 27 Jun, 2013 03:47 PM

    Ondina D.F.'s Avatar

    if in the mediator I use view.addEventListener(CareerEvent.OPEN_POPUP,passEvent); instead of addViewListener than robotlegs tries to destroy it but it fails.

    If you add event listeners using addViewListener, the listeners are removed automatically by robotlegs when the mediator is destroyed. That’s not the case for event listeners added directly to the view. If you don’t remove the listeners manually, they can keep a reference to the view; views and/or mediators are therefore not eligible for gc. It’s a common cause for memory leaks. You sureley don’t want to use it as a workaround for your problem;)

  3. Support Staff 3 Posted by Ondina D.F. on 02 Jul, 2013 06:56 AM

    Ondina D.F.'s Avatar

    Have you sorted this out? Can the thread be closed?

  4. Ondina D.F. closed this discussion on 09 Jul, 2013 01:44 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac