Move destroy window and glfw to CoreInstnace from render engine

This commit is contained in:
Jiga228
2025-10-05 14:25:01 +07:00
parent f60b8aa6b4
commit e7d5cf920e
2 changed files with 12 additions and 9 deletions
+11 -4
View File
@@ -63,14 +63,18 @@ CoreInstance::CoreInstance()
window_ = glfwCreateWindow(800, 600, main_config_.game_name.c_str(), nullptr, nullptr); window_ = glfwCreateWindow(800, 600, main_config_.game_name.c_str(), nullptr, nullptr);
if (window_ == nullptr) if (window_ == nullptr)
{ {
glfwTerminate(); std::cout << "[!] Init render engine: Fail create window\n";
throw std::runtime_error("Fail create window"); return;
} }
try {
render_engine_ = new RenderEngine(*this, window_); render_engine_ = new RenderEngine(*this, window_);
} catch (const std::exception& e)
{
std::cout << "[!] Init render engine: " << e.what() << '\n';
throw;
}
game_ = GameFactory(*this); game_ = GameFactory(*this);
if (game_ == nullptr)
throw std::runtime_error("Fail create game instance!");
} }
CoreInstance::~CoreInstance() CoreInstance::~CoreInstance()
@@ -81,6 +85,9 @@ CoreInstance::~CoreInstance()
delete render_engine_; delete render_engine_;
delete game_; delete game_;
glfwDestroyWindow(window_);
glfwTerminate();
} }
void CoreInstance::start() void CoreInstance::start()
-4
View File
@@ -972,10 +972,6 @@ RenderEngine::~RenderEngine()
if (instance_ != VK_NULL_HANDLE) if (instance_ != VK_NULL_HANDLE)
vkDestroyInstance(instance_, nullptr); vkDestroyInstance(instance_, nullptr);
if (window_ != nullptr)
glfwDestroyWindow(window_);
glfwTerminate();
} }
void RenderEngine::start() void RenderEngine::start()