mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Avoid creating the window twice (#10566)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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};
|
||||
};
|
||||
|
||||
@@ -54,6 +54,6 @@ public:
|
||||
private:
|
||||
int32_t _width{0};
|
||||
int32_t _height{0};
|
||||
bool isInit{false};
|
||||
bool _isWindowCreated{false};
|
||||
};
|
||||
} // namespace cc
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user