在QT中多次绑定创建窗口句柄会出现不能渲染的问题。
win_ = SDL_CreateWindowFrom(this->win_id_);
原因是SDL中SDL_CreateWindowFrom的源码中
void
SDL_DestroyWindow(SDL_Window * window)
{
SDL_VideoDisplay *display;
CHECK_WINDOW_MAGIC(window, );
/* Restore video mode, etc. */
SDL_HideWindow(window);/*注意这个地方哦*/
/* Make sure this window no longer has focus */
if (SDL_GetKeyboardFocus() == window) {
SDL_SetKeyboardFocus(NULL);
}
if (SDL_GetMouseFocus() == window) {
SDL_SetMouseFocus(NULL);
}
/* make no context current if this is the current context window. */
if (window->flags & SDL_WINDOW_OPENGL) {
if (_this->current_glwin == window) {
SDL_GL_MakeCurrent(window, NULL);
}
}
if (window->surface) {
window->surface->flags &= ~SDL_DONTFREE;
SDL_FreeSurface(window->surface);
}
if (_this->DestroyWindowFramebuffer) {
_this->DestroyWindowFramebuffer(_this, window);
}
if (_this->DestroyWindow) {
_this->DestroyWindow(_this, window);
}
if (window->flags & SDL_WINDOW_OPENGL) {
SDL_GL_UnloadLibrary();
}
display = SDL_GetDisplayForWindow(window);
if (display->fullscreen_window == window) {
display->fullscreen_window = NULL;
}
/* Now invalidate magic */
window->magic = NULL;
/* Free memory associated with the window */
SDL_free(window->title);
SDL_FreeSurface(window->icon);
SDL_free(window->gamma);
while (window->data) {
SDL_WindowUserData *data = window->data;
window->data = data->next;
SDL_free(data->name);
SDL_free(data);
}
/* Unlink the window from the list */
if (window->next) {
window->next->prev = window->prev;
}
if (window->prev) {
window->prev->next = window->next;
} else {
_this->windows = window->next;
}
SDL_free(window);
}
有这么一段SDL_HideWindow(window);代码,因此需要解决办法就是在创建好窗口以后需要调用
SDL_ShowWindow(window);
这里的window是创建的窗口句柄。
上面的源代码参考https://www.cnblogs.com/lihaiping/p/4324315.html