Author Topic: Infinite loop in localization  (Read 1822 times)

Cabal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 16
    • View Profile
Infinite loop in localization
« 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

Cabal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 16
    • View Profile
Re: Infinite loop in localization
« Reply #1 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Infinite loop in localization
« Reply #2 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?