From 4cba9d336a05bab367ce430d4f7f20f3d5f200cb Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 23 Jan 2014 17:00:42 -0700 Subject: [PATCH] Fix render issues with main preview widget - I seem to have fixed ths issues with the main preview widget. It seems you just need to set the right window attributes to stop it from breaking. Though when opengl is enabled, there appears to be a weird background glitch in the Qt stuff -- I'm not entirely sure what's going on. Bug in Qt? Also fixed the layout issues, and the widget now properly resizes and centers in to its parent widget. - Prevent the render loop from accessing data if the data isn't valid. Because obs->data is freed before the graphics stuff, it can cause the graphics to keep trying to query the obs->data.displays_mutex after it had already been destroyed. --- libobs/obs-data.h | 2 ++ libobs/obs-video.c | 3 +++ libobs/obs.c | 6 +++-- obs/forms/OBSBasic.ui | 48 +++++++++++++++++++++++---------------- obs/obs-app.cpp | 2 ++ obs/qt-display.hpp | 11 +++++---- obs/window-basic-main.cpp | 27 +++++++++++++--------- 7 files changed, 62 insertions(+), 37 deletions(-) diff --git a/libobs/obs-data.h b/libobs/obs-data.h index 0549b84a6..2dc99e545 100644 --- a/libobs/obs-data.h +++ b/libobs/obs-data.h @@ -88,6 +88,8 @@ struct obs_data { pthread_mutex_t displays_mutex; pthread_mutex_t outputs_mutex; pthread_mutex_t encoders_mutex; + + volatile bool valid; }; struct obs_subsystem { diff --git a/libobs/obs-video.c b/libobs/obs-video.c index 738af426a..235e804d2 100644 --- a/libobs/obs-video.c +++ b/libobs/obs-video.c @@ -92,6 +92,9 @@ static inline void render_displays(void) { size_t i; + if (!obs->data.valid) + return; + /* render extra displays/swaps */ pthread_mutex_lock(&obs->data.displays_mutex); diff --git a/libobs/obs.c b/libobs/obs.c index eb8b02160..b9d51d1f4 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -243,11 +243,11 @@ static bool obs_init_data(void) if (pthread_mutex_init(&data->encoders_mutex, &attr) != 0) goto fail; - success = true; + data->valid = true; fail: pthread_mutexattr_destroy(&attr); - return success; + return data->valid; } static void obs_free_data(void) @@ -255,6 +255,8 @@ static void obs_free_data(void) struct obs_data *data = &obs->data; uint32_t i; + data->valid = false; + for (i = 0; i < MAX_CHANNELS; i++) obs_set_output_source(i, NULL); diff --git a/obs/forms/OBSBasic.ui b/obs/forms/OBSBasic.ui index 550f84698..7f4d29fb9 100644 --- a/obs/forms/OBSBasic.ui +++ b/obs/forms/OBSBasic.ui @@ -8,7 +8,7 @@ 0 0 927 - 703 + 700 @@ -36,24 +36,34 @@ 0 - - - - - - 0 - 0 - - - - - 32 - 32 - - - - - + + + 32 + 32 + + + + + + 50 + 30 + 32 + 32 + + + + + 0 + 0 + + + + + 32 + 32 + + + diff --git a/obs/obs-app.cpp b/obs/obs-app.cpp index e40be0464..8a5c9bb83 100644 --- a/obs/obs-app.cpp +++ b/obs/obs-app.cpp @@ -26,7 +26,9 @@ #include "window-basic-main.hpp" #include "platform.hpp" +#ifdef _WIN32 #include +#endif using namespace std; diff --git a/obs/qt-display.hpp b/obs/qt-display.hpp index 8cf7a45f9..f14acaf74 100644 --- a/obs/qt-display.hpp +++ b/obs/qt-display.hpp @@ -6,14 +6,15 @@ class OBSQTDisplay : public QWidget { Q_OBJECT public: - inline OBSQTDisplay(QWidget *parent = 0, Qt::WindowFlags f = 0) - : QWidget(parent, f) + inline OBSQTDisplay(QWidget *parent = 0, Qt::WindowFlags flags = 0) + : QWidget(parent, flags) { - setAutoFillBackground(false); - setAttribute(Qt::WA_OpaquePaintEvent); - setAttribute(Qt::WA_NativeWindow); setAttribute(Qt::WA_PaintOnScreen); + setAttribute(Qt::WA_StaticContents); setAttribute(Qt::WA_NoSystemBackground); + setAttribute(Qt::WA_OpaquePaintEvent); + setAttribute(Qt::WA_DontCreateNativeAncestors); + setAttribute(Qt::WA_NativeWindow); } virtual QPaintEngine *paintEngine() const {return nullptr;} diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index 4f0f17e0f..f36ed344a 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -281,28 +281,33 @@ bool OBSBasic::InitAudio() void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy) { double targetAspect, baseAspect; - QSize targetSize, newSize; + QSize targetSize; + int x, y; /* resize preview panel to fix to the top section of the window */ targetSize = ui->previewContainer->size(); targetAspect = double(targetSize.width()) / double(targetSize.height()); baseAspect = double(cx) / double(cy); - if (targetAspect > baseAspect) - newSize = QSize(targetSize.height() * baseAspect, - targetSize.height()); - else - newSize = QSize(targetSize.width(), - targetSize.width() / baseAspect); + if (targetAspect > baseAspect) { + cx = targetSize.height() * baseAspect; + cy = targetSize.height(); + } else { + cx = targetSize.width(); + cy = targetSize.width() / baseAspect; + } - //ui->preview->resize(newSize); + x = targetSize.width() /2 - cx/2; + y = targetSize.height()/2 - cy/2; + + ui->preview->setGeometry(x, y, cx, cy); graphics_t graphics = obs_graphics(); - /*if (graphics) { + if (graphics && isVisible()) { gs_entercontext(graphics); - gs_resize(newSize.width(), newSize.height()); + gs_resize(cx, cy); gs_leavecontext(); - }*/ + } } void OBSBasic::closeEvent(QCloseEvent *event)