Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GzSceneManager: Prevent crash 💥 when inserted from menu #1371

Merged
merged 5 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}