0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-19 20:32:15 +02:00

UI: Initialize YoutubeChatDock chat input members in constructor

Currently, the chat input elements (lineEdit, sendButton, and
chatLayout) are initialized when the QCefWidget gets set. This is
problematic behavior that only happened to work because we're a bit
lucky: The chat is only enabled after a widget is set, and it's only set
once. Without those conditions, the chat dock would crash when enabling
the chat before a widget is set, and the elements would get recreated if
the widget is set a second time, resulting in the original elements not
getting freed and leaking.
Moving the element creation to the constructor fixes both of these
problems, as now they're created immediately and only once.

Detected by PVS-Studio.
This commit is contained in:
gxalpha 2024-06-09 14:09:57 +02:00 committed by Lain
parent f462ffb224
commit 7cd5ede1e0
2 changed files with 10 additions and 7 deletions

View File

@ -350,7 +350,7 @@ std::shared_ptr<Auth> YoutubeAuth::Login(QWidget *owner,
}
#ifdef BROWSER_AVAILABLE
void YoutubeChatDock::SetWidget(QCefWidget *widget_)
YoutubeChatDock::YoutubeChatDock(const QString &title) : BrowserDock(title)
{
lineEdit = new LineEditAutoResize();
lineEdit->setVisible(false);
@ -364,6 +364,14 @@ void YoutubeChatDock::SetWidget(QCefWidget *widget_)
chatLayout->addWidget(lineEdit, 1);
chatLayout->addWidget(sendButton);
QWidget::connect(lineEdit, &LineEditAutoResize::returnPressed, this,
&YoutubeChatDock::SendChatMessage);
QWidget::connect(sendButton, &QPushButton::pressed, this,
&YoutubeChatDock::SendChatMessage);
}
void YoutubeChatDock::SetWidget(QCefWidget *widget_)
{
QVBoxLayout *layout = new QVBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(widget_, 1);
@ -373,11 +381,6 @@ void YoutubeChatDock::SetWidget(QCefWidget *widget_)
widget->setLayout(layout);
setWidget(widget);
QWidget::connect(lineEdit, &LineEditAutoResize::returnPressed, this,
&YoutubeChatDock::SendChatMessage);
QWidget::connect(sendButton, &QPushButton::pressed, this,
&YoutubeChatDock::SendChatMessage);
cefWidget.reset(widget_);
}

View File

@ -21,7 +21,7 @@ private:
QHBoxLayout *chatLayout;
public:
inline YoutubeChatDock(const QString &title) : BrowserDock(title) {}
YoutubeChatDock(const QString &title);
void SetWidget(QCefWidget *widget_);
void SetApiChatId(const std::string &id);