cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
8.18k stars 1.93k forks source link

doCreateSurface in MTLSwapchain.m on iOS platform not implemented #16344

Closed LuoLuoDev closed 1 year ago

LuoLuoDev commented 1 year ago

Use Case

I use cocos creator on the iOS platform to nest the cocos view on the native page, and can repeatedly enter the cococ view page.

Problem Description

I found that there is an implementation of the doCreateSurface interface on the Android platform, but there is no corresponding implementation on the iOS platform. This This has led to inconsistencies between functions on the Android and iOS platforms.

Proposed Solution

I would like to ask whether the doCreateSurface interface of the iOS platform will be implemented in the near future.

How it works

No response

Alternatives Considered

maybe you can clear the old metallayer and its resource when pause event happend, and then repalce with the new metallayer new page when resume event happened.

Additional Information

No response

LuoLuoDev commented 1 year ago

doCreateSurface in MTLSwapchain.m on iOS Platform @minggo looking forward to your reply, thx very much.

minggo commented 1 year ago

The program created with cocos should be a separate program. It can not be reentered. Even implement doCreateSurfaceView can not fix it, as engines codes use singleton object in many places.

LuoLuoDev commented 1 year ago

The program created with cocos should be a separate program. It can not be reentered. Even implement doCreateSurfaceView can not fix it, as engines codes use singleton object in many places.

Got it, I have encountered the need to enter the cocos page multiple times. Currently, I refer to the implementation of doInit to implement the doCreateSurfaceView interface, and use the WindowRecreated event to trigger it. When the last cocos page receives dealloc, it will call logic similar to applicationWillTerminate in this class of AppDelegateBridge. In addition, I also did:

  1. SystemWindow::closeWindow() blocks the call to exit(0);
  2. Shielding of JsbBridge closeListener logic
  3. Shielding of JsbBridgeWrapper closeListener logic

above is all i did to try to make reentering possible. If you have any suggestions, please let me know.

minggo commented 1 year ago

Except singleton object, there are many static variables too. And script system is not friendly to enter cocos page multiple times. As I said, currently games created by cocos is not designed to be entered multiple times. You may modify engine to do it, but it is very hard. And I don't know how to do it correctly.

LuoLuoDev commented 1 year ago

Thx for your patient reply. Btw,you just mentioned script system is not friendly, do you mean v8 or jsbridge communication module?

minggo commented 1 year ago

I mean two things:

LuoLuoDev commented 1 year ago

Got it. Currently, I processed them like this:

  1. v8(ScriptEngine) : when I reenter mutil cocos pages , I will keep use script engine like singleton (I just call _platform->loop() once at the time of the first cocos page inited). When the last cocos page receives dealloc, I will call _platform->onDestroy() which will call ~ScriptEngine().
  2. jsbbridge: I keep use it like origin, only make it not released in closeListener callback.