修复Vulkan Surface没有释放问题,丰富部分日志

This commit is contained in:
2026-01-04 21:46:26 +08:00
parent 473e5b57df
commit 3f5f4a8cc0
8 changed files with 37 additions and 14 deletions

View File

@@ -31,6 +31,12 @@ namespace mirai {
surface_ = surface;
}
if (!SDL_SetWindowTitle(win_ptr, config.title.c_str())) {
SDL_DestroyWindow(win_ptr);
return MAKE_ERROR_INFO(error_code::window_creation_failed,
"SDL_SetWindowTitle 失败: {}", SDL_GetError());
}
window_ = win_ptr;
return {};
}
@@ -52,6 +58,15 @@ namespace mirai {
SDL_SetWindowPosition(window_, pos.x(), pos.y());
}
std::string window::get_window_title() {
const char* title = SDL_GetWindowTitle(window_);
if (!title) {
MIRAI_LOG_ERROR("SDL_GetWindowTitle 失败: {}", SDL_GetError());
return "";
}
return std::string(title);
}
vec2i window::get_pos() const {
int x, y;
if (!SDL_GetWindowPosition(window_, &x, &y)) {
@@ -69,6 +84,7 @@ namespace mirai {
void window::on_destroying() {
object::on_destroying();
MIRAI_LOG_INFO("窗口 {} 销毁", get_window_title());
SDL_Vulkan_DestroySurface(vulkan_context::get().get_vk_instance(), surface_, nullptr);
SDL_DestroyWindow(window_);
window_ = nullptr;