Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Cabal on January 21, 2015, 04:12:23 PM

Title: Infinite loop in localization
Post by: Cabal on January 21, 2015, 04:12:23 PM
Hi,

I just upgraded to NGUI 3.7.9 and am running into an infinite loop in the localization code.

I have a text field with a UILocalize script on it.
When the UILocalize starts, it calls OnLocalize on itself and because there is no localization loaded yet, this calls Localization.Get.
localizationHasBeenSet is false so LoadDictionary gets called which sets localizationHasBeenSet to true and calls Set for the language and the dictionary.
The Set function sets localizationHasBeenSet back to false and broadcasts OnLocalize again.

This eventually blows up the stack (infinite recursion) and crashes Unity.

Is anybody else seeing this? Am I missing something?

Stephane
Title: Re: Infinite loop in localization
Post by: Cabal on January 21, 2015, 04:39:00 PM
As a local workaround I have added a "bool relocalize" parameter to Localization::Set(string, Dictionary) (so 3 parameters now)
and I moved the following code inside an if statement in the function so it only runs when the function is called from Load(), not from Set()

...
if (relocalize)
{
     localizationHasBeenSet = false;
     if (onLocalize != null) onLocalize();
     UIRoot.Broadcast("OnLocalize");
}

Not sure if this is the proper fix but it gets rid of the infinite loop and I can still switch languages afterwards (not that I do not have any localized string on screen when I switch the language, so I'm not sure if this path will work properly)

I am unstuck but let me know if there is a better way to solve the issue.
Title: Re: Infinite loop in localization
Post by: ArenMook on January 22, 2015, 11:30:32 AM
I don't quite follow this one... localizationHasBeenSet only gets set to 'false' if the mLanguage has not been set, but mLanguage gets set either inside the Set() function, the same LoadCSV function that set localizationHasBeenSet to 'false', or even in the same Get() function, so what clears it for you?