Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Package`In App Purchasing` may touch endless recursive process in UnityEditor

Discussion in 'Unity IAP' started by JokeMaker, Jan 8, 2020.

  1. JokeMaker

    JokeMaker

    Joined:
    Sep 9, 2019
    Posts:
    19
    In UnityEngine.Purchasing.PurchasingManager
    Code (CSharp):
    1.  
    2. private void CheckForInitialization()
    3. {
    4.   if (!this.initialized)
    5.   {
    6.     bool flag = false;
    7.     foreach (Product product in this.products.set)
    8.     {
    9.       if (!product.availableToPurchase)
    10.         this.m_Logger.LogFormat(LogType.Warning, "Unavailable product {0} -{1}", (object) product.definition.id, (object) product.definition.storeSpecificId);
    11.       else
    12.         flag = true;
    13.     }
    14.     if (flag)
    15.       this.m_Listener.OnInitialized((IStoreController) this);
    16.     else
    17.       this.OnSetupFailed(InitializationFailureReason.NoProductsAvailable);
    18.     this.initialized = true;
    19.   }
    20.   else
    21.   {
    22.     if (this.m_AdditionalProductsCallback == null)
    23.       return;
    24.     this.m_AdditionalProductsCallback();
    25.   }
    26. }
    I find this:
    Code (CSharp):
    1.  
    2. if (flag)
    3.       this.m_Listener.OnInitialized((IStoreController) this);
    4.     else
    5.       this.OnSetupFailed(InitializationFailureReason.NoProductsAvailable);
    6.     this.initialized = true;
    7. ```
    8.  
    9. I suggest this:
    10. ```
    11.     this.initialized = true;
    12. if (flag)
    13.       this.m_Listener.OnInitialized((IStoreController) this);
    14.     else
    15.       this.OnSetupFailed(InitializationFailureReason.NoProductsAvailable);
    16.  
    Imagine this in UnityEditor(Just in UnityEditor):
    Code (CSharp):
    1.  
    2. public void OnInitialized (IStoreController controller, IExtensionProvider extensions)
    3. {
    4.     this.controller = controller;
    5.     this.extensions = extensions;
    6.  
    7.     ......
    8.    
    9.     this.controller.FetchAdditionalProducts(...)
    10. }
    11.  
    I don't know whether it make sense or not~
     
  2. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Thank you for your report, this may cause the following loop, I will confirm with the development team.
    CheckForInitialization() --> this.m_Listener.OnInitialized((IStoreController) this); --> FetchAdditionalProducts --> CheckForInitialization()
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Why would you call FetchAdditionalProducts in Intialization, what would be the use case?
     
  4. JokeMaker

    JokeMaker

    Joined:
    Sep 9, 2019
    Posts:
    19
    Our project has hundreds of iap products. We want to fetch some of them first and then others.
     
  5. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    226
    Hello,

    I can confirm this is still causing an endless loop, but we have plans to fix this.
    Until then, would calling FetchAdditionalProducts after the initialization is done be an option to avoid this?
     
  6. JokeMaker

    JokeMaker

    Joined:
    Sep 9, 2019
    Posts:
    19
    You are right. Nice Day!