From b8f8b5306bcbb3b04c5a3b4ed150bf0100ab672f Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Fri, 4 Mar 2022 08:28:23 -0800 Subject: [PATCH] =?UTF-8?q?GzSceneManager:=20Prevent=20crash=20?= =?UTF-8?q?=F0=9F=92=A5=20when=20inserted=20from=20menu=20(#1371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Louise Poubel Signed-off-by: ahcorde Co-authored-by: ahcorde --- .../plugins/scene_manager/GzSceneManager.cc | 22 +++++++++++++ .../plugins/scene_manager/GzSceneManager.hh | 2 ++ .../plugins/scene_manager/GzSceneManager.qml | 32 ++++++++++++++----- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/gui/plugins/scene_manager/GzSceneManager.cc b/src/gui/plugins/scene_manager/GzSceneManager.cc index 48c0735f10..68d8a666c0 100644 --- a/src/gui/plugins/scene_manager/GzSceneManager.cc +++ b/src/gui/plugins/scene_manager/GzSceneManager.cc @@ -17,6 +17,9 @@ #include #include +#include + +#include #include "../../GuiRunner.hh" #include "GzSceneManager.hh" @@ -67,6 +70,9 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// \brief Indicates whether initial visual plugins have been loaded or not. public: bool initializedVisualPlugins = false; + + /// \brief Whether the plugin was correctly initialized + public: bool initialized{false}; }; } } @@ -90,14 +96,30 @@ void GzSceneManager::LoadConfig(const tinyxml2::XMLElement *) if (this->title.empty()) this->title = "Scene Manager"; + static bool done{false}; + if (done) + { + std::string msg{"Only one GzSceneManager is supported at a time."}; + ignerr << msg << std::endl; + QQmlProperty::write(this->PluginItem(), "message", + QString::fromStdString(msg)); + return; + } + done = true; + ignition::gui::App()->findChild< ignition::gui::MainWindow *>()->installEventFilter(this); + + this->dataPtr->initialized = true; } ////////////////////////////////////////////////// void GzSceneManager::Update(const UpdateInfo &_info, EntityComponentManager &_ecm) { + if (!this->dataPtr->initialized) + return; + IGN_PROFILE("GzSceneManager::Update"); this->dataPtr->renderUtil.UpdateECM(_info, _ecm); diff --git a/src/gui/plugins/scene_manager/GzSceneManager.hh b/src/gui/plugins/scene_manager/GzSceneManager.hh index ab0d5f1be0..34208e0b33 100644 --- a/src/gui/plugins/scene_manager/GzSceneManager.hh +++ b/src/gui/plugins/scene_manager/GzSceneManager.hh @@ -34,6 +34,8 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// This plugin doesn't instantiate a new 3D scene. Instead, it relies on /// another plugin being loaded alongside it that will create and paint the /// scene to the window, such as `ignition::gui::plugins::Scene3D`. + /// + /// Only one GzSceneManager can be used at a time. class GzSceneManager : public GuiSystem { Q_OBJECT diff --git a/src/gui/plugins/scene_manager/GzSceneManager.qml b/src/gui/plugins/scene_manager/GzSceneManager.qml index 873da30014..42595c179f 100644 --- a/src/gui/plugins/scene_manager/GzSceneManager.qml +++ b/src/gui/plugins/scene_manager/GzSceneManager.qml @@ -15,14 +15,30 @@ * */ -import QtQuick 2.0 -import QtQuick.Controls 2.0 +import QtQuick 2.9 +import QtQuick.Controls 2.1 import QtQuick.Layouts 1.3 -// TODO: remove invisible rectangle, see -// https://github.com/ignitionrobotics/ign-gui/issues/220 -Rectangle { - visible: false - Layout.minimumWidth: 100 - Layout.minimumHeight: 100 +GridLayout { + columns: 1 + columnSpacing: 10 + Layout.minimumWidth: 350 + Layout.minimumHeight: 200 + anchors.fill: parent + anchors.margins: 10 + + property string message: 'This plugin updates a 3D scene based on information coming from the Entity-Component-Manager.' + + Label { + Layout.columnSpan: 1 + Layout.fillWidth: true + wrapMode: Text.WordWrap + text: message + } + + Item { + Layout.columnSpan: 1 + width: 10 + Layout.fillHeight: true + } }