mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-05 11:03:31 +00:00
UI: Use weak source for projectors
The projectors were holding on to a reference of a source, even if the source was deleted.
This commit is contained in:
parent
9116ceab6e
commit
0553ddcec0
|
@ -16,11 +16,12 @@ static bool updatingMultiview = false, mouseSwitching, transitionOnDoubleClick;
|
|||
|
||||
OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor,
|
||||
ProjectorType type_)
|
||||
: OBSQTDisplay(widget, Qt::Window),
|
||||
source(source_),
|
||||
removedSignal(obs_source_get_signal_handler(source), "remove",
|
||||
OBSSourceRemoved, this)
|
||||
: OBSQTDisplay(widget, Qt::Window), weakSource(OBSGetWeakRef(source_))
|
||||
{
|
||||
OBSSource source = GetSource();
|
||||
destroyedSignal.Connect(obs_source_get_signal_handler(source),
|
||||
"destroy", OBSSourceDestroyed, this);
|
||||
|
||||
isAlwaysOnTop = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
||||
"ProjectorAlwaysOnTop");
|
||||
|
||||
|
@ -103,6 +104,7 @@ OBSProjector::~OBSProjector()
|
|||
GetDisplay(), isMultiview ? OBSRenderMultiview : OBSRender,
|
||||
this);
|
||||
|
||||
OBSSource source = GetSource();
|
||||
if (source)
|
||||
obs_source_dec_showing(source);
|
||||
|
||||
|
@ -157,7 +159,7 @@ void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy)
|
|||
return;
|
||||
|
||||
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
||||
OBSSource source = window->source;
|
||||
OBSSource source = window->GetSource();
|
||||
|
||||
uint32_t targetCX;
|
||||
uint32_t targetCY;
|
||||
|
@ -191,11 +193,11 @@ void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy)
|
|||
obs_source_dec_showing(source);
|
||||
obs_source_inc_showing(curSource);
|
||||
source = curSource;
|
||||
window->source = source;
|
||||
window->weakSource = OBSGetWeakRef(source);
|
||||
}
|
||||
} else if (window->type == ProjectorType::Preview &&
|
||||
!main->IsPreviewProgramMode()) {
|
||||
window->source = nullptr;
|
||||
window->weakSource = nullptr;
|
||||
}
|
||||
|
||||
if (source)
|
||||
|
@ -206,7 +208,7 @@ void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy)
|
|||
endRegion();
|
||||
}
|
||||
|
||||
void OBSProjector::OBSSourceRemoved(void *data, calldata_t *params)
|
||||
void OBSProjector::OBSSourceDestroyed(void *data, calldata_t *params)
|
||||
{
|
||||
OBSProjector *window = reinterpret_cast<OBSProjector *>(data);
|
||||
QMetaObject::invokeMethod(window, "EscapeTriggered");
|
||||
|
@ -367,7 +369,7 @@ void OBSProjector::UpdateProjectorTitle(QString name)
|
|||
|
||||
OBSSource OBSProjector::GetSource()
|
||||
{
|
||||
return source;
|
||||
return OBSGetStrongRef(weakSource);
|
||||
}
|
||||
|
||||
ProjectorType OBSProjector::GetProjectorType()
|
||||
|
@ -410,6 +412,7 @@ void OBSProjector::OpenFullScreenProjector()
|
|||
int monitor = sender()->property("monitor").toInt();
|
||||
SetMonitor(monitor);
|
||||
|
||||
OBSSource source = GetSource();
|
||||
UpdateProjectorTitle(QT_UTF8(obs_source_get_name(source)));
|
||||
}
|
||||
|
||||
|
@ -426,6 +429,7 @@ void OBSProjector::OpenWindowedProjector()
|
|||
|
||||
savedMonitor = -1;
|
||||
|
||||
OBSSource source = GetSource();
|
||||
UpdateProjectorTitle(QT_UTF8(obs_source_get_name(source)));
|
||||
screen = nullptr;
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ class OBSProjector : public OBSQTDisplay {
|
|||
Q_OBJECT
|
||||
|
||||
private:
|
||||
OBSSource source;
|
||||
OBSSignal removedSignal;
|
||||
OBSWeakSourceAutoRelease weakSource;
|
||||
OBSSignal destroyedSignal;
|
||||
|
||||
static void OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy);
|
||||
static void OBSRender(void *data, uint32_t cx, uint32_t cy);
|
||||
static void OBSSourceRemoved(void *data, calldata_t *params);
|
||||
static void OBSSourceDestroyed(void *data, calldata_t *params);
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
|
Loading…
Reference in a new issue