From 8e9db6a2fe663621105b0a19d5a4e7c1f73845e7 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Fri, 11 Jul 2025 00:26:52 -0500 Subject: [PATCH] Display an informational dialog when OpenGL cannot properly be initialized --- scwx-qt/source/scwx/qt/gl/gl_context.cpp | 60 +++++++++++++++++------ scwx-qt/source/scwx/qt/main/main.cpp | 19 ++++++- scwx-qt/source/scwx/qt/map/map_widget.cpp | 12 +++-- 3 files changed, 69 insertions(+), 22 deletions(-) diff --git a/scwx-qt/source/scwx/qt/gl/gl_context.cpp b/scwx-qt/source/scwx/qt/gl/gl_context.cpp index 11cfb4d9..4729eab5 100644 --- a/scwx-qt/source/scwx/qt/gl/gl_context.cpp +++ b/scwx-qt/source/scwx/qt/gl/gl_context.cpp @@ -3,12 +3,9 @@ #include #include +#include -namespace scwx -{ -namespace qt -{ -namespace gl +namespace scwx::qt::gl { static const std::string logPrefix_ = "scwx::qt::gl::gl_context"; @@ -63,16 +60,49 @@ void GlContext::Impl::InitializeGL() const GLenum error = glewInit(); if (error != GLEW_OK) { - logger_->error("glewInit failed: {}", - reinterpret_cast(glewGetErrorString(error))); + auto glewErrorString = + reinterpret_cast(glewGetErrorString(error)); + logger_->error("glewInit failed: {}", glewErrorString); + + QMessageBox::critical( + nullptr, + "Supercell Wx", + QString("Unable to initialize OpenGL: %1").arg(glewErrorString)); + + throw std::runtime_error("Unable to initialize OpenGL"); } - logger_->info("OpenGL Version: {}", - reinterpret_cast(glGetString(GL_VERSION))); - logger_->info("OpenGL Vendor: {}", - reinterpret_cast(glGetString(GL_VENDOR))); - logger_->info("OpenGL Renderer: {}", - reinterpret_cast(glGetString(GL_RENDERER))); + auto glVersion = reinterpret_cast(glGetString(GL_VERSION)); + auto glVendor = reinterpret_cast(glGetString(GL_VENDOR)); + auto glRenderer = reinterpret_cast(glGetString(GL_RENDERER)); + + logger_->info("OpenGL Version: {}", glVersion); + logger_->info("OpenGL Vendor: {}", glVendor); + logger_->info("OpenGL Renderer: {}", glRenderer); + + // Get OpenGL version + GLint major = 0; + GLint minor = 0; + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); + + if (major < 3 || (major == 3 && minor < 3)) + { + logger_->error( + "OpenGL 3.3 or greater is required, found {}.{}", major, minor); + + QMessageBox::critical( + nullptr, + "Supercell Wx", + QString("OpenGL 3.3 or greater is required, found %1.%2\n\n%3\n%4\n%5") + .arg(major) + .arg(minor) + .arg(glVersion) + .arg(glVendor) + .arg(glRenderer)); + + throw std::runtime_error("OpenGL version too low"); + } glGenTextures(1, &textureAtlas_); @@ -151,6 +181,4 @@ std::size_t GlContext::Impl::GetShaderKey( return seed; } -} // namespace gl -} // namespace qt -} // namespace scwx +} // namespace scwx::qt::gl diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index 321f1b15..fbb716c9 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -151,8 +151,23 @@ int main(int argc, char* argv[]) // Run Qt main loop { scwx::qt::main::MainWindow w; - w.show(); - result = a.exec(); + + bool initialized = false; + + try + { + w.show(); + initialized = true; + } + catch (const std::exception& ex) + { + logger_->critical(ex.what()); + } + + if (initialized) + { + result = a.exec(); + } } } diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 763be1b6..d619de79 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -2011,10 +2011,14 @@ void MapWidgetImpl::RadarProductViewConnect() std::shared_ptr radarSite = radarProductManager_->radar_site(); - RadarRangeLayer::Update( - map_, - radarProductView->range(), - {radarSite->latitude(), radarSite->longitude()}); + if (map_ != nullptr) + { + RadarRangeLayer::Update( + map_, + radarProductView->range(), + {radarSite->latitude(), radarSite->longitude()}); + } + widget_->update(); Q_EMIT widget_->RadarSweepUpdated(); },