From a88b04a29e9581f3ab9d60b897cec0d26411f34b Mon Sep 17 00:00:00 2001 From: Raphael Dumusc Date: Thu, 1 Feb 2018 18:13:45 +0100 Subject: [PATCH] QmlStreamer bugfix: gracefully exit on Stream connection error A previous change made the Stream constructor throw, causing an uncaught exception. --- CMakeLists.txt | 2 +- deflect/qt/QmlStreamerImpl.cpp | 29 ++++++++++++++++------------- deflect/qt/QmlStreamerImpl.h | 2 +- doc/Changelog.md | 4 ++++ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d9cacba..84f051d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # Daniel Nachbaur cmake_minimum_required(VERSION 3.1 FATAL_ERROR) -project(Deflect VERSION 0.14.0) +project(Deflect VERSION 0.14.1) set(Deflect_VERSION_ABI 7) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/common) diff --git a/deflect/qt/QmlStreamerImpl.cpp b/deflect/qt/QmlStreamerImpl.cpp index d92ddfe..7c09d02 100644 --- a/deflect/qt/QmlStreamerImpl.cpp +++ b/deflect/qt/QmlStreamerImpl.cpp @@ -1,7 +1,7 @@ /*********************************************************************/ -/* Copyright (c) 2015-2016, EPFL/Blue Brain Project */ -/* Daniel.Nachbaur */ -/* Raphael Dumusc */ +/* Copyright (c) 2015-2018, EPFL/Blue Brain Project */ +/* Daniel.Nachbaur */ +/* Raphael Dumusc */ /* All rights reserved. */ /* */ /* Redistribution and use in source and binary forms, with or */ @@ -105,10 +105,18 @@ void QmlStreamer::Impl::_afterRender(const QImage image) if (!_sendFuture.valid() || !_sendFuture.get()) return; - if (!_stream && !_setupDeflectStream()) + if (!_stream) { - qWarning() << "Could not setup Deflect stream"; - return; + try + { + _setupDeflectStream(); + } + catch (const std::runtime_error& e) + { + qWarning() << e.what(); + _onStreamClosed(); + return; + } } if (image.isNull()) @@ -248,16 +256,13 @@ std::string QmlStreamer::Impl::_getDeflectStreamIdentifier() const return streamId.empty() ? DEFAULT_STREAM_ID : streamId; } -bool QmlStreamer::Impl::_setupDeflectStream() +void QmlStreamer::Impl::_setupDeflectStream() { if (!_stream) _stream.reset(new Stream(_getDeflectStreamIdentifier(), _streamHost)); - if (!_stream->isConnected()) - return false; - if (!_stream->registerForEvents()) - return false; + throw std::runtime_error("Stream failed to register for events"); if (_sizeHints != SizeHints()) _stream->sendSizeHints(_sizeHints); @@ -297,8 +302,6 @@ bool QmlStreamer::Impl::_setupDeflectStream() connect(_eventReceiver.get(), &EventReceiver::closed, this, &QmlStreamer::Impl::_onStreamClosed); - - return true; } void QmlStreamer::Impl::_connectTouchInjector() diff --git a/deflect/qt/QmlStreamerImpl.h b/deflect/qt/QmlStreamerImpl.h index 2f6ab41..b98690f 100644 --- a/deflect/qt/QmlStreamerImpl.h +++ b/deflect/qt/QmlStreamerImpl.h @@ -96,7 +96,7 @@ private slots: void _send(QKeyEvent& keyEvent); bool _sendToWebengineviewItems(QKeyEvent& keyEvent); std::string _getDeflectStreamIdentifier() const; - bool _setupDeflectStream(); + void _setupDeflectStream(); void _connectTouchInjector(); void _setupMouseModeSwitcher(); diff --git a/doc/Changelog.md b/doc/Changelog.md index 7229552..efc6e73 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -3,6 +3,10 @@ Changelog {#Changelog} ## Deflect 0.14 +### 0.14.1 (git master) +* [192](https://github.com/BlueBrain/Deflect/pull/192): + QmlStreamer bugfix: gracefully exit if the stream connection fails. + ### 0.14.0 (23-10-2017) * [191](https://github.com/BlueBrain/Deflect/pull/191):