libgdx / gdx-pay

A libGDX cross-platform API for InApp purchasing.
Apache License 2.0
225 stars 83 forks source link

Crash on iOS #198

Closed keesvandieren closed 5 years ago

keesvandieren commented 5 years ago

Please ensure you have given all the following requested information in your report.

We see some crashes in Fabric related to gdx-pay. Not got any crashes myself.

Issue details, reproduction steps/code

gdx-pay version: 0.12.1

We see crashes in Fabric. Most iPhone X (78%), 99% of users has iOS 12.

Version of gdx-pay and/or relevant dependencies

0.12.1

Stacktrace

Fatal Exception: java.lang.IllegalArgumentException
java.lang.IllegalArgumentException: No strong ref exists from <SKPaymentQueue: 0x28178e100> (a org.robovm.apple.storekit.SKPaymentQueue) to <j_com_badlogic_gdx_pay_ios_apple_PurchaseManageriOSApple$PromotionTransactionObserver: 0x28178e210> a (com.badlogic.gdx.pay.ios.apple.PurchaseManageriOSApple$PromotionTransactionObserver) at org.robovm.objc.ObjCObject$AssociatedObjectHelper.removeStrongRef(ObjCObject.java:689) at org.robovm.objc.ObjCObject.removeStrongRef(ObjCObject.java:220) at com.badlogic.gdx.pay.ios.apple.PurchaseManageriOSApple$IosFetchProductsAndInstallDelegate.didReceiveResponse(PurchaseManageriOSApple.java:327) at com.badlogic.gdx.pay.ios.apple.PurchaseManageriOSApple$IosFetchProductsAndInstallDelegate.$cb$productsRequest$didReceiveResponse$(PurchaseManageriOSApple.java) at org.robovm.apple.uikit.UIApplication.main(Native Method) at org.robovm.apple.uikit.UIApplication.main(UIApplication.java:428) at com.squins.tkl.ios.common.IosLauncher$Companion.start(IosLauncher.kt:280) at com.squins.tkl.ios.es.IosEsLauncher$Companion.main(IosEsLauncher.kt:22) at com.squins.tkl.ios.es.IosEsLauncher.main(IosEsLauncher.kt)

Please select the affected platforms and payment service implementation

We have set 'shouldProcessPromotionalStorePayment' to false. Kotlin implementation:

object : PurchaseManageriOSApple() {

        override fun shouldProcessPromotionalStorePayment(queue: SKPaymentQueue?, payment: SKPayment?, product: SKProduct?) =
                // can only be true if we initialize gdx-pay on startup, before doing Dagger.
                false
    }
MrStahlfelge commented 5 years ago

I checked the code. The strong ref is added, and the IosFetchProductsAndInstallDelegate is started later and makes sure the strong ref is only removed once. Strong ref operations are synchronized, so it's also unlikely that we have some kind of race condition here. I would suggest to catch the IllegalArgumentException around line 327 so that startupTransactionObserver is nulled afterwards and the app continues to launch - what do you think?

keesvandieren commented 5 years ago

@MrStahlfelge submitted a PR for it, if you have some time to review, would be great :-)

keesvandieren commented 5 years ago

Still got the crash:

Fatal Exception: java.lang.IllegalArgumentException
java.lang.IllegalArgumentException: No strong ref exists from <SKPaymentQueue: 0x2813373d0>
(a org.robovm.apple.storekit.SKPaymentQueue)
 to <j_com_badlogic_gdx_pay_ios_apple_PurchaseManageriOSApple$PromotionTransactionObserver: 0x2813373b0>
 a (com.badlogic.gdx.pay.ios.apple.PurchaseManageriOSApple$PromotionTransactionObserver)
 at org.robovm.objc.ObjCObject$AssociatedObjectHelper.removeStrongRef(ObjCObject.java:689)
 at org.robovm.objc.ObjCObject.removeStrongRef(ObjCObject.java:220)
 at com.badlogic.gdx.pay.ios.apple.PurchaseManageriOSApple$IosFetchProductsAndInstallDelegate.didReceiveResponse(PurchaseManageriOSApple.java:332)
 at com.badlogic.gdx.pay.ios.apple.PurchaseManageriOSApple$IosFetchProductsAndInstallDelegate.$cb$productsRequest$didReceiveResponse$(PurchaseManageriOSApple.java)
 at org.robovm.apple.uikit.UIApplication.main(Native Method) at org.robovm.apple.uikit.UIApplication.main(UIApplication.java:428)
 at com.squins.tkl.ios.common.IosLauncher$Companion.start(IosLauncher.kt:280) at com.squins.tkl.ios.es.IosEsLauncher$Companion.main(IosEsLauncher.kt:22)
 at com.squins.tkl.ios.es.IosEsLauncher.main(IosEsLauncher.kt)

So synchronisation is not the issue. Add try-catch block around it then?

MrStahlfelge commented 5 years ago

That will help for sure and I think it is an acceptable option here.

MrStahlfelge commented 5 years ago

Made a change, let us know if it helps by closing this issue. :)

keesvandieren commented 5 years ago

Took a while, new app with this gdx-pay just got accepted, now have to wait for 1-2 weeks to see the results

keesvandieren commented 5 years ago

No longer appearing. Thanks for your efforts