I came across another incident of Cairngorm throwing a stack overflow error.

I had a Cairngorm ModelLocator named AppModelLocator (my subclass). In it, I
declared a class variable that instantiated another class like so:

public var currentProfile : MemberProfile = new MemberProfile();



And in the MemberProfile.as class, I create a reference back to the model:

private var model :AppModelLocator = AppModelLocator.getInstance();



What this did is create an infinitely recursive loop I guess, because
AppModelLocator.as creates an instance of MemberProfile so it would try to
get an instance of itself which would instantiate MemberProfile again, ad
infinitum.

So, in AppModelLocator.as, I changed

public var currentProfile : MemberProfile = new MemberProfile();



to

public var currentProfile : MemberProfile;



And in the constructor I assigned it:

currentProfile = new MemberProfile(modelLocator);
// not shown: modelLocator is the private static var modelLocator
:AppModelLocator, standard Cairngorm usage



I still had to pass modelLocator as a parameter to MemberProfile() to avoid
using AppModelLocator.getInstance within, which would cause the inifnite
loop.


Then in MemberProfile.as:

private var model :AppModelLocator;

public function MemberProfile( modelLocator :AppModelLocator)
{
    model = modelLocator;
}


So the bottom line:
You cannot use the  `private var model :AppModelLocator =
AppModelLocator.getInstance();`  convention of creating a reference to your
model inside of a class that is instantiated WITHIN the model!! It causes an
infinite loop. Instead do it as I describe above.

-Carlos Saenz-


jer_ela wrote:
> 
> I am getting a stack overflow error #1023 in a place that it doesn't
> make any sense, which I can get rid of by doing things that don't
> reduce the depth of the stack.
> 
-- 
View this message in context: 
http://www.nabble.com/Unusual-error-tp12261893p14413267.html
Sent from the FlexCoders mailing list archive at Nabble.com.

Reply via email to