From a396343646829566872e32168144bd68e310b477 Mon Sep 17 00:00:00 2001 From: T1ti <40864460+T1ti@users.noreply.github.com> Date: Mon, 26 Aug 2024 03:34:28 +0200 Subject: [PATCH] adspartan : MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit noggit: application: add failsafe for when the opengl context creatio… …n get stuck https://github.com/wowdev/noggit3/commit/3e4f41e158bb9b711d1173b5e315c083c72b2117 --- src/noggit/MapChunk.cpp | 2 +- src/noggit/ModelInstance.cpp | 2 +- src/noggit/application/NoggitApplication.cpp | 31 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/noggit/MapChunk.cpp b/src/noggit/MapChunk.cpp index 4ec63dc3..1656eed1 100755 --- a/src/noggit/MapChunk.cpp +++ b/src/noggit/MapChunk.cpp @@ -57,7 +57,7 @@ MapChunk::MapChunk(MapTile* maintile, BlizzardArchive::ClientFile* f, bool bigAl // xbase = header.xpos; // ybase = header.ypos; - texture_set = nullptr; + texture_set.reset(); auto& tile_buffer = mt->getChunkHeightmapBuffer(); int chunk_start = (px * 16 + py) * mapbufsize * 4; diff --git a/src/noggit/ModelInstance.cpp b/src/noggit/ModelInstance.cpp index d31ad8b2..64eee77e 100755 --- a/src/noggit/ModelInstance.cpp +++ b/src/noggit/ModelInstance.cpp @@ -115,7 +115,7 @@ std::vector> ModelInstance::intersect (glm::mat4x4 con bool ModelInstance::isInFrustum(const math::frustum& frustum) { - if (_need_recalc_extents && model->finishedLoading()) + if (_need_recalc_extents) { recalcExtents(); } diff --git a/src/noggit/application/NoggitApplication.cpp b/src/noggit/application/NoggitApplication.cpp index 005414a8..f15bb4c2 100755 --- a/src/noggit/application/NoggitApplication.cpp +++ b/src/noggit/application/NoggitApplication.cpp @@ -2,10 +2,35 @@ #include #include +#include +#include +#include + #include #include #include +namespace +{ + std::atomic_bool success = false; + + void opengl_context_creation_stuck_failsafe() + { + for (int i = 0; i < 50; ++i) + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + if (success.load()) + { + return; + } + } + + LogError << "OpenGL Context creation failed (timeout), closing..." << std::endl; + + std::terminate(); + } +} + namespace Noggit::Application { void NoggitApplication::initalize(int argc, char* argv[], std::vector Parser) @@ -163,6 +188,10 @@ namespace Noggit::Application bool doAntiAliasing = app_settings.value("anti_aliasing", false).toBool(); format.setSamples(doAntiAliasing ? 4 : applicationConfiguration.GraphicsConfiguration.SamplesCount); // default is 0, no AA + // context creation seems to get stuck sometimes, this ensure the app is killed + // otherwise it's wasting cpu resources and is annoying when developping + auto failsafe = std::async(&opengl_context_creation_stuck_failsafe); + QSurfaceFormat::setDefaultFormat(format); QOpenGLContext context; context.create(); @@ -172,6 +201,8 @@ namespace Noggit::Application context.makeCurrent(&surface); + success = true; + OpenGL::context::scoped_setter const _(::gl, &context); GLint majVers = 0, minVers = 0;