diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index 9d965be31..b48d272c5 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -90,6 +90,8 @@ extern "C" { #include <86box/timer.h> #include <86box/nvr.h> extern int qt_nvr_save(void); + +bool cpu_thread_running = false; } void qt_set_sequence_auto_mnemonic(bool b); @@ -444,6 +446,7 @@ main_thread_fn() } } + cpu_thread_running = false; is_quit = 1; for (uint8_t i = 1; i < GFXCARD_MAX; i ++) { if (gfxcard[i]) { @@ -736,6 +739,7 @@ main(int argc, char *argv[]) #endif plat_pause(0); + cpu_thread_running = true; main_thread = new std::thread(main_thread_fn); }); diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 7e0cecdeb..85bc0de55 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -62,6 +62,8 @@ extern int qt_nvr_save(void); #ifdef MTR_ENABLED # include #endif + +extern bool cpu_thread_running; }; #include @@ -1256,7 +1258,7 @@ MainWindow::eventFilter(QObject *receiver, QEvent *event) static auto curdopause = dopause; if (event->type() == QEvent::WindowBlocked) { curdopause = dopause; - plat_pause(1); + plat_pause(isShowMessage ? 2 : 1); emit setMouseCapture(false); } else if (event->type() == QEvent::WindowUnblocked) { plat_pause(curdopause); @@ -1279,7 +1281,11 @@ void MainWindow::showMessage(int flags, const QString &header, const QString &message) { if (QThread::currentThread() == this->thread()) { - showMessage_(flags, header, message); + if (!cpu_thread_running) { + showMessageForNonQtThread(flags, header, message, nullptr); + } + else + showMessage_(flags, header, message); } else { std::atomic_bool done = false; emit showMessageForNonQtThread(flags, header, message, &done); @@ -1295,6 +1301,7 @@ MainWindow::showMessage_(int flags, const QString &header, const QString &messag if (done) { *done = false; } + isShowMessage = true; QMessageBox box(QMessageBox::Warning, header, message, QMessageBox::NoButton, this); if (flags & (MBX_FATAL)) { box.setIcon(QMessageBox::Critical); @@ -1306,6 +1313,7 @@ MainWindow::showMessage_(int flags, const QString &header, const QString &messag if (done) { *done = true; } + isShowMessage = false; if (cpu_thread_run == 0) QApplication::exit(-1); } diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index dced698bb..479ed38a4 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -182,6 +182,9 @@ private: friend class RendererCommon; friend class RendererStack; // For UI variable access by non-primary renderer windows. friend class WindowsRawInputFilter; // Needed to reload renderers on style sheet changes. + + + bool isShowMessage = false; }; #endif // QT_MAINWINDOW_HPP diff --git a/src/qt/qt_openglrenderer_pcem.cpp b/src/qt/qt_openglrenderer_pcem.cpp index 4644dc7be..c8f3d3eb9 100644 --- a/src/qt/qt_openglrenderer_pcem.cpp +++ b/src/qt/qt_openglrenderer_pcem.cpp @@ -1,6 +1,8 @@ #include "qt_renderercommon.hpp" #include "qt_mainwindow.hpp" +extern MainWindow* main_window; + #include #include #include @@ -26,6 +28,7 @@ extern "C" { #include <86box/86box.h> #include <86box/plat.h> +#include <86box/ui.h> #include <86box/video.h> #include <86box/path.h> #include <86box/ini.h> @@ -33,6 +36,7 @@ extern "C" { #include <86box/qt-glslp-parser.h> char gl3_shader_file[MAX_USER_SHADERS][512]; +extern bool cpu_thread_running; } #define SCALE_SOURCE 0 @@ -132,7 +136,7 @@ OpenGLRendererPCem::create_program(struct shader_program *program) glw.glGetProgramiv(program->id, GL_INFO_LOG_LENGTH, &maxLength); char *log = (char *) malloc(maxLength); glw.glGetProgramInfoLog(program->id, maxLength, &length, log); - QMessageBox::critical((QWidget *) qApp->findChild(), tr("GLSL Error"), tr("Program not linked:\n%1").arg(log)); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Program not linked:\n\n%1").arg(log)); // wx_simple_messagebox("GLSL Error", "Program not linked:\n%s", log); free(log); return 0; @@ -177,7 +181,7 @@ OpenGLRendererPCem::compile_shader(GLenum shader_type, const char *prepend, cons glw.glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); char *log = (char *) malloc(length); glw.glGetShaderInfoLog(shader, length, &length, log); - QMessageBox::critical((QWidget *) qApp->findChild(), tr("GLSL Error"), tr("Could not compile shader:\n%1").arg(log)); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not compile shader:\n\n%1").arg(log)); // wx_simple_messagebox("GLSL Error", "Could not compile shader:\n%s", log); pclog("Could not compile shader: %s\n", log); @@ -580,7 +584,8 @@ OpenGLRendererPCem::load_glslp(glsl_t *glsl, int num_shader, const char *f) pclog("Load texture %s...\n", file); if (!load_texture(file, &tex->texture)) { - QMessageBox::critical((QWidget *) qApp->findChild(), tr("GLSL Error"), tr("Could not load texture: %s").arg(file)); + //QMessageBox::critical(main_window, tr("GLSL Error"), tr("Could not load texture: %s").arg(file)); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load texture: %s").arg(file)); pclog("Could not load texture %s!\n", file); failed = 1; break; @@ -626,7 +631,7 @@ OpenGLRendererPCem::load_glslp(glsl_t *glsl, int num_shader, const char *f) pclog("Creating pass %u (%s)\n", (i + 1), pass->alias); pclog("Loading shader %s...\n", shader->shader_fn); if (!shader->shader_program) { - QMessageBox::critical((QWidget *) qApp->findChild(), tr("GLSL Error"), tr("Could not load shader: %1").arg(shader->shader_fn)); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load shader: %1").arg(shader->shader_fn)); // wx_simple_messagebox("GLSL Error", "Could not load shader: %s", shader->shader_fn); pclog("Could not load shader %s\n", shader->shader_fn); failed = 1; @@ -764,8 +769,7 @@ OpenGLRendererPCem::OpenGLRendererPCem(QWidget *parent) #else format.setVersion(3, 2); #endif - format.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); - format.setOption(QSurfaceFormat::DebugContext); + format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) format.setRenderableType(QSurfaceFormat::OpenGLES); @@ -1031,7 +1035,7 @@ OpenGLRendererPCem::initialize() for (auto &flag : buf_usage) flag.test_and_set(); - QMessageBox::critical((QWidget *) qApp->findChild(), tr("Error initializing OpenGL"), e.what() + tr("\nFalling back to software rendering.")); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("Error initializing OpenGL"), e.what() + tr("\nFalling back to software rendering.")); context->doneCurrent(); isFinalized = true; diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 561c94d8a..35dbc0081 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -385,6 +385,7 @@ plat_munmap(void *ptr, size_t size) #endif } +extern bool cpu_thread_running; void plat_pause(int p) { @@ -392,6 +393,10 @@ plat_pause(int p) wchar_t title[1024]; wchar_t paused_msg[512]; + if (!cpu_thread_running && p == 1) { + p = 2; + } + if ((!!p) == dopause) { #ifdef Q_OS_WINDOWS if (source_hwnd)