diff --git a/gui/src/main.cpp b/gui/src/main.cpp index 2780db4..eb95488 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -161,7 +161,6 @@ int RunMain(QApplication &app, Settings *settings) int RunStream(QApplication &app, const StreamSessionConnectInfo &connect_info) { StreamWindow window(connect_info); - window.show(); app.setQuitOnLastWindowClosed(true); return app.exec(); } diff --git a/gui/src/mainwindow.cpp b/gui/src/mainwindow.cpp index d894d0e..2fd87e4 100644 --- a/gui/src/mainwindow.cpp +++ b/gui/src/mainwindow.cpp @@ -225,15 +225,7 @@ void MainWindow::ServerItemWidgetTriggered() QString host = server->GetHostAddr(); StreamSessionConnectInfo info(settings, host, server->registered_host.GetRPRegistKey(), server->registered_host.GetRPKey()); - try - { - auto stream_window = new StreamWindow(info); - stream_window->show(); - } - catch(const ChiakiException &e) - { - QMessageBox::critical(this, tr("Stream failed"), e.what()); - } + new StreamWindow(info); } else { diff --git a/gui/src/streamwindow.cpp b/gui/src/streamwindow.cpp index 2d440b6..ee99a92 100644 --- a/gui/src/streamwindow.cpp +++ b/gui/src/streamwindow.cpp @@ -25,18 +25,29 @@ StreamWindow::StreamWindow(const StreamSessionConnectInfo &connect_info, QWidget *parent) : QMainWindow(parent) { - session = new StreamSession(connect_info, this); + try + { + session = new StreamSession(connect_info, this); - connect(session, &StreamSession::SessionQuit, this, &StreamWindow::SessionQuit); + connect(session, &StreamSession::SessionQuit, this, &StreamWindow::SessionQuit); - av_widget = new AVOpenGLWidget(session->GetVideoDecoder(), this); - setCentralWidget(av_widget); + av_widget = new AVOpenGLWidget(session->GetVideoDecoder(), this); + setCentralWidget(av_widget); - grabKeyboard(); + grabKeyboard(); - session->Start(); + session->Start(); - resize(connect_info.video_profile.width, connect_info.video_profile.height); + resize(connect_info.video_profile.width, connect_info.video_profile.height); + show(); + } + catch(const Exception &e) + { + session = nullptr; + av_widget = nullptr; + QMessageBox::critical(this, tr("Stream failed"), tr("Failed to initialize Stream Session: %1").arg(e.what())); + close(); + } } StreamWindow::~StreamWindow() @@ -47,17 +58,20 @@ StreamWindow::~StreamWindow() void StreamWindow::keyPressEvent(QKeyEvent *event) { - session->HandleKeyboardEvent(event); + if(session) + session->HandleKeyboardEvent(event); } void StreamWindow::keyReleaseEvent(QKeyEvent *event) { - session->HandleKeyboardEvent(event); + if(session) + session->HandleKeyboardEvent(event); } void StreamWindow::closeEvent(QCloseEvent *) { - session->Stop(); + if(session) + session->Stop(); } void StreamWindow::SessionQuit(ChiakiQuitReason reason, const QString &reason_str)