[SOLVED] [ANDROID][CocosJS - v3.9] Crash IAP when GooglePlay Request return result successful data!

Manytimes, my app crashed when I change Scene manytimes with log, but always:
D/IAP(22137): GooglePlay Request result : 0 msg : Product request successful. data :[{“id”:"***",“title”:"***",“currencyCode”:"***",“price”:"***",“desc”:"***",“priceValue”:***}]
07-19 22:45:01.346: A/libc(22137): Fatal signal 11 (SIGSEGV) at 0x00000031 (code=1), thread 22152 (Thread-4902)

I’m using CocosJS v3.9, and SDKBox V2.2.2.12. I call sdkbox.PluginIAP.init() once time when app start first time!

That log just means google play initialized with empty information for IAP dosen’t say where it crashed. Can you show the full crash log?

Hi @nite, this is full log. But I have some secret infomation, character ‘***’ in my log is correct info. Sorry about this.log.zip (5.6 KB)

When my app crash, always this some line:
IAP(): GooglePlay Request result : 0 msg : Product request successful. data …
: A/libc(): Fatal signal 11 (SIGSEGV) at 0x00000031 …
I use sdkbox_config.json in assets/res. Sometimes app crashes, not always. Thanks @nite .

Seem, the listener in SDKBox has a bug. When I comment :
sdkbox.IAP.setListener({…});
My app don’t crash. And crash is always in step: C ++ JSbìnding .
@nite Do you know when listener have been removed, because I change other scene, I run requestListProduct, IAP have “Product request successful” but in onProductRequestSuccess in sdkbox.IAP listener no catch event.

We were not able to reproduce this issue with our standard sample https://github.com/sdkbox/sdkbox-sample-iap,
would you kindly send us your project and let us know the steps to follow and conditions to meet (if there is any) in order to reproduce the issue?
Thanks, Ryan

Hi ryanjjj, I have 2 file js:

  • GateIAP.js: is a file control flow InApp Purchase
  • IAPLayer.js: is a layer to render UI.
    Steps to meet this issue:
  1. In Scene1, I go to IAPLayer => it’s ok, products show OK
  2. Exit IAPLayer and go to Scene2, Scene2 is also add IAPLayer.
  3. Go to IAPLayer.
  4. You can repeat that steps many time and sometimes app will crashes.
    I try other ways to resolve this issues but not ok. :(.
    This is 2 files js: js.zip (1.6 KB)
    Thank ryanjjj!

I have updated all plugins’ JS binding because of callback would crash after gc (__jsc__. garbageCollect()).

Please update the file and help to test.
Thank you.

PluginIAPJSHelper.cpp (13.9 KB)

Thanks yinjimmy,i will test.

Hi yinjimmy, i use your file PluginIAPJSHelper.cpp . While i’m compling, it’s error:

jni/…/…/Classes/PluginIAPJSHelper.cpp:281:14: error: no type named ‘Maybe’ in namespace ‘mozilla’
mozilla::MaybeJS::PersistentRootedValue _jsCallbackRef;
jni/…/…/Classes/PluginIAPJSHelper.cpp:281:19: error: expected member name or ‘;’ after declaration specifiers
mozilla::MaybeJS::PersistentRootedValue _jsCallbackRef;
jni/…/…/Classes/PluginIAPJSHelper.cpp:286:25: error: use of undeclared identifier ‘ScriptingCore’
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
^
jni/…/…/Classes/PluginIAPJSHelper.cpp:287:9: error: use of undeclared identifier ‘_jsCallbackRef’
_jsCallbackRef.construct(cx, JS::NullHandleValue);
^
jni/…/…/Classes/PluginIAPJSHelper.cpp:291:9: error: use of undeclared identifier ‘_jsCallbackRef’
_jsCallbackRef.destroyIfConstructed();
^
jni/…/…/Classes/PluginIAPJSHelper.cpp:296:13: error: use of undeclared identifier ‘_jsCallbackRef’
_jsCallbackRef.ref() = func;

Can you review this file? Thanks!

Or holding the callback function like:

sdkbox.PluginIAP.callback = function() {
}

Do u tell me more clearly? Do you want unuse sdkbox.IAP.setListener() ?

sorry for mess.

// hold 
        sdkbox.IAP.callback = {
            onSuccess : function (product) {
                //Purchase success
                cc.log("Purchase successful: " + product.name)
            },
            onFailure : function (product, msg) {
                //Purchase failed
                //msg is the error message
                cc.log("Purchase failed: " + product.name + " error: " + msg);
            },
            onCanceled : function (product) {
                //Purchase was canceled by user
                cc.log("Purchase canceled: " + product.name);
            },
            onRestored : function (product) {
                //Purchase restored
                cc.log("Restored: " + product.name);
            },
            onProductRequestSuccess : function (products) {
                self.menuIAP.removeAllChildren();
                //Returns you the data for all the iap products
                //You can get each item using following method
                for (var i = 0; i < products.length; i++) {
                    cc.log("================");
                    cc.log("name: " + products[i].name);
                    cc.log("price: " + products[i].price);
                    cc.log("================");

                    (function() {
                        var name = products[i].name;
                        var btn = new cc.MenuItemFont(name, function() {
                            cc.log("purchase: " + name);
                            sdkbox.IAP.purchase(name);
                        });
                        self.menuIAP.addChild(btn);
                    }());
                }
                self.menuIAP.alignItemsVerticallyWithPadding(5);
            },
            onProductRequestFailure : function (msg) {
                //When product refresh request fails.
                cc.log("Failed to get products");
            }
        };

// set
        sdkbox.IAP.setListener(sdkbox.IAP.callback);
1 Like

Thanks a lot yinjimmy! I tested many times but my app didn’t crash.

great to hear that

1 Like