Author Topic: Localization bug: clears current locale when duplicated  (Read 2589 times)

Konstantin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Localization bug: clears current locale when duplicated
« on: April 17, 2014, 08:57:51 AM »
Let's assume we have a scene with Localization script. It is loaded twice and Localization is duplicated. The second instance will destroy itself, but it will also break static fields. Here is some code from Localization.cs:

  1. void Awake ()
  2. {
  3.         if (mInstance == null) // mInstance is not null, this is the second Localization
  4.         {
  5.         ...
  6.         }
  7.         else Destroy(gameObject); // Destroy duplicate which will call OnDisable
  8. }
  9.  
  10. void OnDisable ()
  11. {
  12.         localizationHasBeenSet = false;
  13.         mLanguageIndex = -1;
  14.         mDictionary.Clear(); // BOOM! current locale texts wiped out
  15.         mOldDictionary.Clear();
  16. }
  17.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Localization bug: clears current locale when duplicated
« Reply #1 on: April 17, 2014, 12:18:26 PM »
Thanks! Add the "if (mInstance != this) return;" to the top of OnDisable.

P.S. There is no reason to add the Localization script to the scene anymore. I strongly advise you to remove it as with the next update you will get errors otherwise.
« Last Edit: April 17, 2014, 01:08:51 PM by ArenMook »