Search Unity

InAppPurchasing Failing Inside Try/Catch Without Throwing Exception

Discussion in 'Editor & General Support' started by lucernagame, Jan 15, 2019.

  1. lucernagame

    lucernagame

    Joined:
    Nov 5, 2018
    Posts:
    19
    I've downloaded the InAppPurchasing package from the store, 1.20.1, and am having troubles running it. I've modified one function as such:

    Code (CSharp):
    1.  
    2.         public void InitializePurchasing()
    3.         {
    4.             Text fl = GameObject.Find("/Canvas/InAppPurchasing/FailureLabel").GetComponent<Text>();
    5.             fl.text += "initializing...";
    6.             if (IsInitialized())
    7.             {
    8.                 fl.text += "[INITIALIZED]";
    9.                 return;
    10.             }
    11.            
    12.             try
    13.             {
    14.                 fl.text += "about_to_build...";
    15.                 var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    16.                 fl.text += "building...";
    17.                 builder.AddProduct(kProductIDConsumable, ProductType.Consumable);
    18.                 builder.AddProduct(kProductIDNonConsumable, ProductType.NonConsumable);
    19.                 builder.AddProduct(kProductIDMonthlySubscription, ProductType.Subscription, new IDs(){
    20.                 { kProductNameAppleSubscription, AppleAppStore.Name },
    21.                 { kProductNameGooglePlaySubscription, GooglePlay.Name },
    22.                 });
    23.  
    24.                 fl.text += "built...";
    25.                 UnityPurchasing.Initialize(this, builder);
    26.  
    27.                 fl.text += "initialized!";
    28.             }
    29.             catch(Exception ex)
    30.             {
    31.                 fl.text += ex.Message + ":" + ex.ToString();
    32.             }
    When in the editor, I get "about_to_build...building...built...initialized!" and the purchase occurs successfully on button press with the debug logs of "ProcessPurchase: PASS. Product: 'TheProduct'" and purchase({0}): TheProduct, as well as the rest of the expected messages.

    When in an Android build, it prints "initializing...about_to_build...building..." then stops. Pressing it again prints the same thing at the end of the message.

    When in Windows, it prints "initializing...about_to_build...Object reference not set to an instance of an object." Although I think I might be able to work through this one since there's so little code to work through, but if anyone has the answer just off the top of their head and could let me know that would be great as it would save me a huge amount of time.

    The Android problem is proving quite the hurdle, as it actually gets past where the Windows build is failing, but doesn't get to the point where it would print "built...". As such I'm working through potential causes of this specific behaviour but it is looking more and more like a bug as I continue to investigate. Can anyone confirm that this is indeed a bug with Unity?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,583
    You would need to determine which object reference is null. I would check fl first.
     
  3. lucernagame

    lucernagame

    Joined:
    Nov 5, 2018
    Posts:
    19
    I've continued to troubleshoot and will be updating this post when I find the solution, so that if I find it far in the future I won't "bump" the post up to the newest part of thread listings and disrupt the more relevant discussions.

    I should also mention (in case I don't end up fixing this), fl doesn't become null or dereferenced when builder.AddProduct() is called in the Windows build. builder just seems to be the nexus of the issue. I've started breaking things down with IDAPro and will be building them back up hopefully in a way that works. I've been pretty happy with Unity's Windows deployments so far, I've never run into an issue where I've had to compromise, hopefully I won't have to here. In contrast, my Tizen / Android / tvOS / etc builds all have semi-unique changes I've had to make for each one to work, but at the very least they're chugging along. As well, thanks for your suggestions so far.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,583