Skip to content

Commit

Permalink
GzSceneManager: Prevent crash 💥 when inserted from menu (#1371)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: ahcorde <[email protected]>

Co-authored-by: ahcorde <[email protected]>
  • Loading branch information
chapulina and ahcorde authored Mar 4, 2022
1 parent 3f91707 commit b8f8b53
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include <map>
#include <set>
#include <string>

#include <QQmlProperty>

#include "../../GuiRunner.hh"
#include "GzSceneManager.hh"
Expand Down Expand Up @@ -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};
};
}
}
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 24 additions & 8 deletions src/gui/plugins/scene_manager/GzSceneManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit b8f8b53

Please sign in to comment.