diff --git a/native/cocos/platform/SDLHelper.cpp b/native/cocos/platform/SDLHelper.cpp index 992e9df756..069345a78a 100644 --- a/native/cocos/platform/SDLHelper.cpp +++ b/native/cocos/platform/SDLHelper.cpp @@ -153,7 +153,7 @@ SDLHelper::~SDLHelper() { SDL_DestroyWindow(_handle); _handle = nullptr; } - if (_windowCreated) { + if (_isWindowCreated) { SDL_Quit(); } } @@ -334,6 +334,9 @@ void SDLHelper::pollEvent(bool *quit) { bool SDLHelper::createWindow(const char *title, int w, int h, int flags) { + if (_isWindowCreated) { + return true; + } SDL_Rect screenRect; if (SDL_GetDisplayUsableBounds(0, &screenRect) != 0) { return false; @@ -346,6 +349,9 @@ bool SDLHelper::createWindow(const char *title, bool SDLHelper::createWindow(const char *title, int x, int y, int w, int h, int flags) { + if (_isWindowCreated) { + return true; + } // Create window int sdlFlags = windowFlagsToSDLWindowFlag(flags); _handle = SDL_CreateWindow(title, x, y, w, h, sdlFlags); @@ -354,7 +360,7 @@ bool SDLHelper::createWindow(const char *title, CC_LOG_ERROR("Window could not be created! SDL_Error: %s\n", SDL_GetError()); return false; } - _windowCreated = true; + _isWindowCreated = true; return true; } diff --git a/native/cocos/platform/SDLHelper.h b/native/cocos/platform/SDLHelper.h index 926e1eebe5..49cb1ca9c6 100644 --- a/native/cocos/platform/SDLHelper.h +++ b/native/cocos/platform/SDLHelper.h @@ -57,7 +57,7 @@ public: private: void dispatchSDLEvent(const SDL_Event& sdlEvent, bool* quit); void dispatchWindowEvent(const SDL_WindowEvent& wevent); - bool _windowCreated{false}; + bool _isWindowCreated{false}; IEventDispatch* _delegate{nullptr}; struct SDL_Window* _handle{nullptr}; }; diff --git a/native/cocos/platform/mac/modules/SystemWindow.h b/native/cocos/platform/mac/modules/SystemWindow.h index 07d6516a3b..edc6eb1e06 100644 --- a/native/cocos/platform/mac/modules/SystemWindow.h +++ b/native/cocos/platform/mac/modules/SystemWindow.h @@ -54,6 +54,6 @@ public: private: int32_t _width{0}; int32_t _height{0}; - bool isInit{false}; + bool _isWindowCreated{false}; }; } // namespace cc diff --git a/native/cocos/platform/mac/modules/SystemWindow.mm b/native/cocos/platform/mac/modules/SystemWindow.mm index a0861a92ee..1431e2ea19 100644 --- a/native/cocos/platform/mac/modules/SystemWindow.mm +++ b/native/cocos/platform/mac/modules/SystemWindow.mm @@ -40,6 +40,10 @@ SystemWindow::~SystemWindow() = default; bool SystemWindow::createWindow(const char* title, int w, int h, int flags) { + if(_isWindowCreated) { + return true; + } + _isWindowCreated = true; _width = w; _height = h; AppDelegate *delegate = [[NSApplication sharedApplication] delegate]; @@ -51,10 +55,10 @@ bool SystemWindow::createWindow(const char* title, bool SystemWindow::createWindow(const char *title, int x, int y, int w, int h, int flags) { - if(isInit) { + if(_isWindowCreated) { return true; } - isInit = true; + _isWindowCreated = true; _width = w; _height = h; AppDelegate *delegate = [[NSApplication sharedApplication] delegate];