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

[Solved] Restore transactions null pointer

Discussion in 'Unity IAP' started by Deathfate, Apr 4, 2016.

Thread Status:
Not open for further replies.
  1. Deathfate

    Deathfate

    Joined:
    Sep 10, 2012
    Posts:
    46
    When I try to restore transactions, the first time the plugin normally works, but if I press restore transactions afterwards, I get a null pointer exception:

    Code (CSharp):
    1. NullReferenceException: A null value was found where an object instance was required.
    2.   at UnityEngine.Purchasing.NativeJSONStore.OnPurchaseFailed (System.String json) [0x00000] in <filename unknown>:0
    3.   at UnityEngine.Purchasing.AppleStoreImpl.ProcessMessage (System.String subject, System.String payload, System.String receipt, System.String transactionId) [0x00000] in <filename unknown>:0
    4.   at UnityEngine.Purchasing.AppleStoreImpl+<MessageCallback>c__AnonStorey0.<>m__0 () [0x00000] in <filename unknown>:0
    5.   at UnityEngine.Purchasing.Extension.UnityUtil.Update () [0x00000] in <filename unknown>:0

    There shouldn't be anything bad with my code as the first time I run the app it normally works.

    I tried to replace restore transactions for Refreshappreceipt and the problem I have is that the first time It does it OK but the second time none of the Actions (whether success or error) gets fired and I only get a log in the console that says:
    RefreshReceipt status 1

    Thank you for your time.
     
  2. Deathfate

    Deathfate

    Joined:
    Sep 10, 2012
    Posts:
    46
    Hmm, I changed my code so I store in a global var the builder and the appleExtension at init and oninit respectively and also I changed the RestoreTransactions to use a function as callback instead of an anonymous function and now it works everytime.

    I think the problem was the anonymous function instead of a normal function
     
    Last edited: Apr 4, 2016
  3. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    This looks like a bug in Unity IAP. Can you still reproduce it?
     
  4. Deathfate

    Deathfate

    Joined:
    Sep 10, 2012
    Posts:
    46
    Yes, make a function like this

    Code (CSharp):
    1.  
    2.   public void RestorePurchases()
    3.   {
    4.     ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    5.     appleConfig = builder.Configure<IAppleConfiguration>();
    6. apple.RestoreTransactions((success)=>{
    7.    Debug.Log("RESTORED "+success);
    8. });
    9. }
    First time, it will restore success, but next time it will give you the null pointer exception I mentioned

    For the RefreshAppReceipt just use the same code but change the RestoreTransactions Line for RefreshAppReceipt and use 2 anon functions again instead of creating a function and then linking it. The first time everything goes well but the second time None of the functions gets called.
     
    Last edited: Apr 4, 2016
  5. nicholasr

    nicholasr

    Joined:
    Aug 15, 2015
    Posts:
    183
    @Deathfate I may be misunderstanding line 5 & 6 around "appleConfig" and "apple". If they are the same, then the IAppleConfiguration does not have the RestoreTransactions method on it. I am unsure how a transaction could be restored successfully with an instance of that configuration.

    Instead the IAppleExtensions (http://docs.unity3d.com/Manual/UnityIAPiOSMAS.html) has a RestoreTransactions method, and can be accessed from the IExtensionProvider instance returned by OnInitialized.

    If, however, `apple` is a global with the IAppleExtensions datatype, then I guess somehow "apple" is being nulled at a time after the first successful RestoreTransactions and before the second. ?
     
  6. Deathfate

    Deathfate

    Joined:
    Sep 10, 2012
    Posts:
    46
    Sorry I didn't paste the code well, i went back in git and this is the exact code that was giving me the null pointer exception the second time i restore purchases:

    Code (CSharp):
    1. /// <summary>
    2.   /// Restores purchases, MAC/iOS only
    3.   /// </summary>
    4.   public void RestorePurchases()
    5.   {
    6.     if (Initialized)
    7.     {
    8.       if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.OSXPlayer)
    9.       {
    10.         // Fetch the Apple store-specific subsystem.
    11.         IAppleExtensions apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    12.         apple.RestoreTransactions((result) =>
    13.         {
    14.           Utils.Log("RestorePurchases result: " + result);
    15.         });
    16.       }
    17.     }
    18.   }
    19.  
    If I change the RestoreTransactions for RefreshAppReceipt and use two anonymous functions, the result was similar as the first time everything went well but the second time none of the anonymous functions (wherther the success or error) where called.
     
  7. Deathfate

    Deathfate

    Joined:
    Sep 10, 2012
    Posts:
    46
    Could you reproduce the bug using the code i mentioned? Thank you.
     
  8. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    I haven't been able to reproduce it. Please could you do this for me:

    1. Modify Assets/Plugins/UnityPurchasing/iOS/UnityPurchasing.m by adding the following at line 269:

    NSLog(@"BEGIN LOG");
    NSLog(@"%@", [NSThread callStackSymbols]);
    NSLog(@"%@", result);
    NSLog(@"END LOG");

    2. Rerun your test and reproduce the problem from your first post
    3. Copy and paste into this thread from the XCode debug log everything between the 'begin' and 'end' logging statements
     
  9. Deathfate

    Deathfate

    Joined:
    Sep 10, 2012
    Posts:
    46
    I am going to be busy and couldn't reply in a month sorry, i will try it as soon as i can
     
  10. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    345
    I am getting the same error with purchase and restore. the purchase is successful, but it doesn't seem like ProcessPurchase is called. When I kill the app and start it again, ProcessPurchase is called and my purchases are handled.

    2016-04-25 16:50:06.515 survival[46172:2394351] UnityIAP:UpdatedTransactions

    NullReferenceException: A null value was found where an object instance was required.

    at UnityEngine.Purchasing.NativeJSONStore.OnPurchaseFailed (System.String json) [0x00000] in <filename unknown>:0

    at UnityEngine.Purchasing.AppleStoreImpl.ProcessMessage (System.String subject, System.String payload, System.String receipt, System.String transactionId) [0x00000] in <filename unknown>:0

    at UnityEngine.Purchasing.AppleStoreImpl+<MessageCallback>c__AnonStorey0.<>m__0 () [0x00000] in <filename unknown>:0

    at UnityEngine.Purchasing.Extension.UnityUtil.Update () [0x00000] in <filename unknown>:0


    will provide log in a few minutes as soon as i get it working..
     
    Last edited: Apr 25, 2016
  11. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    345
    If i attempt to buy, but cancel the transaction i get the log..
    If i do actually buy, and the purchase is successful (says apple prompt), but with the failing error above, there is no log (doesn't even seem to be going inside the function)..

    -(void) purchaseProduct:(ProductDefinition*)productDef also gets called twice when I click on my IAP button. the first time productDef is nil, the 2nd time it is my actual IAP.

    2016-04-25 17:41:24.244 survival[46229:2404952] BEGIN LOG
    2016-04-25 17:41:24.344 survival[46229:2404952] (
    0 survival 0x00106699 -[UnityPurchasing onPurchaseFailed:reason:] + 298
    1 survival 0x00106975 -[UnityPurchasing paymentQueue:updatedTransactions:] + 540
    2 StoreKit 0x2ec41f41 <redacted> + 84
    3 CoreFoundation 0x2524ed21 CFArrayApplyFunction + 36
    4 StoreKit 0x2ec41edd <redacted> + 128
    5 StoreKit 0x2ec427d9 <redacted> + 1044
    6 StoreKit 0x2ec43167 <redacted> + 122
    7 StoreKit 0x2ec41df9 <redacted> + 144
    8 libdispatch.dylib 0x04695b7f _dispatch_call_block_and_release + 10
    9 libdispatch.dylib 0x04695b6b _dispatch_client_callout + 22
    10 libdispatch.dylib 0x0469a655 _dispatch_main_queue_callback_4CF + 1680
    11 CoreFoundation 0x25301bdd <redacted> + 8
    12 CoreFoundation 0x253000d7 <redacted> + 1574
    13 CoreFoundation 0x2524f2e9 CFRunLoopRunSpecific + 520
    14 CoreFoundation 0x2524f0d5 CFRunLoopRunInMode + 108
    15 GraphicsServices 0x2683fac9 GSEventRunModal + 160
    16 UIKit 0x299140b9 UIApplicationMain + 144
    17 survival 0x000dca1b main + 202
    18 libdyld.dylib 0x24ef7873 <redacted> + 2
    )
    2016-04-25 17:41:24.355 survival[46229:2404952] {"reason":"UserCancelled","productId":"hat_3"}
    2016-04-25 17:41:24.355 survival[46229:2404952] END LOG
    -> applicationDidBecomeActive()
    NullReferenceException: A null value was found where an object instance was required.
    at UnityEngine.Purchasing.AppleStoreImpl+<MessageCallback>c__AnonStorey0.<>m__0 () [0x00000] in <filename unknown>:0
    at UnityEngine.Purchasing.AppleStoreImpl.ProcessMessage (System.String subject, System.String payload, System.String receipt, System.String transactionId) [0x00000] in <filename unknown>:0
    at UnityEngine.Purchasing.AppleStoreImpl+<MessageCallback>c__AnonStorey0.<>m__0 () [0x00000] in <filename unknown>:0
    at UnityEngine.Purchasing.Extension.UnityUtil.Update () [0x00000] in <filename unknown>:0
     
    Last edited: Apr 25, 2016
  12. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @Deathfate @mrm83 I believe this is caused by you creating more than one ConfigurationBuilder - you should only create one at the start of your Application and maintain a reference to it if necessary for obtaining extended configuration.

    Code (CSharp):
    1. // Only do this once.
    2. var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    Doing this shouldn't break your running payments though, that will be fixed in a forthcoming update.
     
  13. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    345
    Yes that fixed it. Thanks.
     
Thread Status:
Not open for further replies.