Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
December 17, 2017, 10:13:05 PM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1]
Print
Author Topic: [BUG?] Constructor of a mediator executed twice at first run  (Read 5428 times)
broadysmile
Newbie
*
Posts: 7


View Profile Email
« on: December 21, 2010, 12:51:06 AM »

As I'm not a native english speaker and don't expect you to understand the title, I'll just show an example:

Add
Code:
trace (NAME + ": ", viewComponent);
in a mediator constructor.

Instantiate ShellMediator once and then WindowMediator twice:
Quote
ShellMediator:  [object Shell]
ShellMediator:  null
WindowMediator:  [object Window]
WindowMediator:  null
WindowMediator:  [object Window]

So it's like when You execute a mediator's constructor first time for the specific class, You get the constructor executed once more without viewComponent argument...

I'm using Fabrication for Flash, everything up-to-date.

I don't know if this is a bug, it just got me alarmed.
Logged
broadysmile
Newbie
*
Posts: 7


View Profile Email
« Reply #1 on: December 31, 2010, 02:20:18 AM »

Not only extra instance of mediator, but also of it's viewComponent is created (I put trace in vc constructor)!

I can't sleep because of it! Will check the issue on new project in 2011.
Logged
rafal.szemraj
Moderator
Full Member
*****
Posts: 41


View Profile WWW
« Reply #2 on: January 03, 2011, 03:42:02 AM »

Hi,

Second constructor call for mediator is caused by reflection mechanism. As you've probably noticed in mediator constructor there is ( and should be ) as less code as possible - main mediator initialization should be done in onRegister() method. You should not be worry of second constructor run - reflection mechanism creates only local variable so it is deleted as soon as all reflection info about mediator instance is gathered. This explanation is only for mediator - I don't know how you managed to have second viewComponent instance created. Can you send me some code? Or maybe put some example in fabrication google code issues section?

Thanks.
Rafał
Logged
broadysmile
Newbie
*
Posts: 7


View Profile Email
« Reply #3 on: January 03, 2011, 05:00:55 AM »

You just interrupted me making a simple program reproducing the problem and there is no extra component created there, so probably it's my fault Roll Eyes.

As for reflection mechanism, thanks, I was expecting something like this going in the background, but as I'm new to the all MVC stuff and I'm making a complex project i was so afraid of memory leaks that I had to ask.

I'll try to either fix, or reproduce my problem with one extra component and report the result here : )

Thanks for Your time, Fabrication is great! (BTW, is it easy to get Fabrication going on HAXE?)
Logged
broadysmile
Newbie
*
Posts: 7


View Profile Email
« Reply #4 on: January 03, 2011, 05:44:06 AM »

I prepared the essence of this bug (component constructor ran once more). I really can't find a mistake in this short code, but maybe I just didn't code it properly for reflection or some other mechanism...

Here is the flashDevelop project:
http://gospoda.oz.pl/vidmo.rar

It traces:
1
2
0

but I only instantiate
new Vidmo(1)
new Vidmo(2)

And trace is only in Vidmo constructor, tracing the number argument.

Thank You in advance.

EDIT: oh, the "0" disappears when I comment out these lines in main command:
registerMediator(new VidmoMediator(shell.vidmo1));
registerMediator(new VidmoMediator(shell.vidmo2));

so it's like the problem is somewhere around, or inside, reflection mechanism.
« Last Edit: January 03, 2011, 05:47:36 AM by broadysmile » Logged
broadysmile
Newbie
*
Posts: 7


View Profile Email
« Reply #5 on: January 04, 2011, 06:30:25 AM »

I enhanced it with:
Code:
var error:Error = new Error();
trace(number, error.getStackTrace().split('\n')[3]);

and got:
Quote
1 undefined
2 undefined
0    at org.as3commons.reflect::Type$/getTypeDescription()[/Users/sema/Work/projects/personal/development/PureMVCFabricationIoC/as3-commons-reflect/org/as3commons/reflect/Type.as:218]
Logged
Pages: [1]
Print
Jump to: