Avoid creating the window twice (#10566)

This commit is contained in:
qiuguohua
2022-03-29 16:26:30 +08:00
committed by GitHub
parent fb40da563d
commit 50d2db2035
4 changed files with 16 additions and 6 deletions
+8 -2
View File
@@ -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;
}
+1 -1
View File
@@ -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];