YoYoGames / GMEXT-GooglePlayBilling

Repository for GameMaker's GooglePlayBilling Extension
Other
6 stars 2 forks source link

[ISSUE] `GPBilling_PurchaseProduct` null object reference (requires call to `GPBilling_QueryProducts`) #6

Closed j4m1ef0rd closed 6 months ago

j4m1ef0rd commented 10 months ago

version 1.0.6 When i try and call GPBilling_PurchaseProduct i get this error:

08-31 14:07:55.504 23235 23258 I yoyo : InvocationTargetException thrown trying to call method GPBilling_PurchaseProduct on GooglePlayBilling
08-31 14:07:55.504 23235 23258 I yoyo : Target exception: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference. Cause: null. Stack trace:
08-31 14:07:55.504 23235 23258 I yoyo : java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
08-31 14:07:55.504 23235 23258 I yoyo : at com.byJamieFord.EvoPet.GooglePlayBillingService.purchaseSku(GooglePlayBillingService.java:534)
08-31 14:07:55.504 23235 23258 I yoyo : at com.byJamieFord.EvoPet.GooglePlayBillingService.purchaseCatalogItem(GooglePlayBillingService.java:566)
08-31 14:07:55.504 23235 23258 I yoyo : at com.byJamieFord.EvoPet.GooglePlayBilling.GPBilling_PurchaseProduct(GooglePlayBilling.java:172)
08-31 14:07:55.504 23235 23258 I yoyo : at java.lang.reflect.Method.invoke(Native Method)
08-31 14:07:55.504 23235 23258 I yoyo : at com.yoyogames.runner.RunnerJNILib.CallExtensionFunction(RunnerJNILib.java:793)
08-31 14:07:55.504 23235 23258 I yoyo : at com.yoyogames.runner.RunnerJNILib.Process(Native Method)
08-31 14:07:55.504 23235 23258 I yoyo : at com.byJamieFord.EvoPet.DemoRenderer.onDrawFrame(DemoRenderer.java:507)
08-31 14:07:55.504 23235 23258 I yoyo : at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1573)
08-31 14:07:55.504 23235 23258 I yoyo : at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)
DiasFranciscoA commented 10 months ago

Hello! The likely reason for the crash is that you need to call GPBilling_QueryProducts before making any purchases. Although this is the probable cause, the extension could be improved to generate an error log instead of causing a crash. We'll work on addressing this issue. In the meantime, you can avoid the crash by ensuring you call GPBilling_QueryProducts beforehand.

j4m1ef0rd commented 10 months ago

Yes that worked. I didn't know it was critical that you call GPBilling_QueryProducts before you can purchase an item. The sample code does not say this at all, the only requirement is that the store is connected. Also the gpb_product_data_response is empty, so this made me think it was not needed.

if (!GPBilling_IsStoreConnected()) exit;