Native build freeze when load and run a new scene


This is the code I`m using to load and run a new scene:

        cc.director.loadScene("scene2", function(_scene){

I expect the scene to load and run when I click a button, In the properties of the button I have added a callback to this method as described here:

The preview in the browser and when I build a web application works fine.
But when I build a native macOS application, the moment I click the button the app freeze.
the reason I believe it is freeze is because the button continue displaying the pressed animation forever and nothing is happening, I am not able to press any other buttons after in the app.

In the build properties I have selected to include all the scenes.
I get a notification the app is from an unknown source but I click ok, so the app launch.
My AV complain the app is trying to modify a file but I click allow and so the app continue to run.

The moment I click a button, the button display the pressed animation and the app freeze, I get no messages.

Is there anything else I could try? What could possibly cause this issue if it works in the browser but freeze in the native build?
Is there any way I could debug the app and get it display any errors?

I have created a project in case someone would like to see exactly how the project looks like: (847.0 KB)

I would appreciate any help.

Ok, the documentation saying I need to run the preview in Simulator to debug the native build.
When I run the preview in Simulator I get the following error in the console at the moment I click the button and the preview freeze:

ERROR: Uncaught TypeError: Cannot read property ‘length’ of null, cocos2d-jsb.js:0:0

Any idea what the problem is?
Running Cocos Creator 2.4.3 on macOS Catalina 10.15.7


Using this code;


Instead of this:

cc.director.loadScene("scene2", function(_scene){

Did solve the problem.
Not sure if it a bug, missing feature or the documentation need to be updated or just something I misunderstood. But it seems loading the scene on it own is enough and works on both native and web.

Hi, as of v2.4, there are two ways to load scenes, so please choose according to your usage. Refer to this document for details.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.