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

Fix crashing on exiting OSG + ImGui applications #1303

Merged
merged 4 commits into from
May 3, 2019
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
## DART 6

### [DART 6.8.4 (2019-XX-XX)](https://github.com/dartsim/dart/milestone/56?closed=1)

#### Changes

* GUI

* Fixed crashing on exiting OSG + ImGui applications: [#1303](https://github.com/dartsim/dart/pull/1303)

#### Compilers Tested

* Linux

* GCC 64-bit: 5.4.0, 7.3.0, 8.2.0
* GCC 32-bit: 5.4.0

* macOS

* AppleClang: 9.1.0, 10.0.0

### [DART 6.8.3 (2019-05-01)](https://github.com/dartsim/dart/milestone/55?closed=1)

#### Changes
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ endif()
# If you change the version, please update the <version> tag in package.xml.
set(DART_MAJOR_VERSION "6")
set(DART_MINOR_VERSION "8")
set(DART_PATCH_VERSION "3")
set(DART_PATCH_VERSION "4")
set(DART_VERSION "${DART_MAJOR_VERSION}.${DART_MINOR_VERSION}.${DART_PATCH_VERSION}")
set(DART_PKG_DESC "Dynamic Animation and Robotics Toolkit.")
set(DART_PKG_EXTERNAL_DEPS "eigen, ccd, fcl, assimp, boost")
Expand Down
1 change: 1 addition & 0 deletions dart/external/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_link_libraries(${target_name} PUBLIC OpenGL::GL)
if(CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(${target_name} PRIVATE -w)
endif()
target_compile_definitions(${target_name} PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS)

# Component
add_component(${PROJECT_NAME} ${component_name})
Expand Down
22 changes: 11 additions & 11 deletions dart/gui/osg/ImGuiHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,35 @@ namespace osg {
//==============================================================================
struct ImGuiNewFrameCallback : public ::osg::Camera::DrawCallback
{
ImGuiNewFrameCallback(ImGuiHandler& handler) : mHandler(handler)
ImGuiNewFrameCallback(ImGuiHandler* handler) : mHandler(handler)
{
// Do nothing
}

virtual void operator()(::osg::RenderInfo& renderInfo) const
{
mHandler.newFrame(renderInfo);
mHandler->newFrame(renderInfo);
}

private:
ImGuiHandler& mHandler;
::osg::ref_ptr<ImGuiHandler> mHandler;
};

//==============================================================================
struct ImGuiDrawCallback : public ::osg::Camera::DrawCallback
{
ImGuiDrawCallback(ImGuiHandler& handler) : mHandler(handler)
ImGuiDrawCallback(ImGuiHandler* handler) : mHandler(handler)
{
// Do nothing
}

virtual void operator()(::osg::RenderInfo& renderInfo) const
{
mHandler.render(renderInfo);
mHandler->render(renderInfo);
}

private:
ImGuiHandler& mHandler;
::osg::ref_ptr<ImGuiHandler> mHandler;
};

//==============================================================================
Expand All @@ -96,9 +96,6 @@ ImGuiHandler::ImGuiHandler()
ImGui::StyleColorsDark();

ImGui_ImplOpenGL2_Init();

ImGuiIO& io = ImGui::GetIO();
io.RenderDrawListsFn = ImGui_ImplOpenGL2_RenderDrawData;
}

//==============================================================================
Expand All @@ -113,10 +110,10 @@ void ImGuiHandler::setCameraCallbacks(::osg::Camera* camera)
if (nullptr == camera)
return;

ImGuiDrawCallback* postDrawCallback = new ImGuiDrawCallback(*this);
ImGuiDrawCallback* postDrawCallback = new ImGuiDrawCallback(this);
camera->setPostDrawCallback(postDrawCallback);

ImGuiNewFrameCallback* preDrawCallback = new ImGuiNewFrameCallback(*this);
ImGuiNewFrameCallback* preDrawCallback = new ImGuiNewFrameCallback(this);
camera->setPreDrawCallback(preDrawCallback);
}

Expand Down Expand Up @@ -282,6 +279,9 @@ void ImGuiHandler::render(::osg::RenderInfo& /*renderInfo*/)
}

ImGui::Render();

auto* drawData = ImGui::GetDrawData();
ImGui_ImplOpenGL2_RenderDrawData(drawData);
}

} // namespace osg
Expand Down
4 changes: 2 additions & 2 deletions dart/gui/osg/ImGuiViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ ImGuiViewer::~ImGuiViewer()
//==============================================================================
ImGuiHandler* ImGuiViewer::getImGuiHandler()
{
return mImGuiHandler;
return mImGuiHandler.get();
}

//==============================================================================
const ImGuiHandler* ImGuiViewer::getImGuiHandler() const
{
return mImGuiHandler;
return mImGuiHandler.get();
}

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion dart/gui/osg/ImGuiViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ImGuiViewer : public Viewer
protected:

/// ImGui handler.
ImGuiHandler* mImGuiHandler;
::osg::ref_ptr<ImGuiHandler> mImGuiHandler;

/// About widget.
std::shared_ptr<AboutWidget> mAboutWidget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ AtlasSimbiconWidget::AtlasSimbiconWidget(
void AtlasSimbiconWidget::render()
{
ImGui::SetNextWindowPos(ImVec2(10,20));
if (!ImGui::Begin("Atlas Control", nullptr, ImVec2(360,340), 0.5f,
ImGui::SetNextWindowSize(ImVec2(360,340));
ImGui::SetNextWindowBgAlpha(0.5f);
if (!ImGui::Begin("Atlas Control", nullptr,
ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_HorizontalScrollbar))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class AtlasSimbiconWorldNode;
class AtlasSimbiconWidget : public dart::gui::osg::ImGuiWidget
{
public:

/// Constructor
AtlasSimbiconWidget(dart::gui::osg::ImGuiViewer* viewer,
AtlasSimbiconWorldNode* node);
Expand All @@ -59,7 +58,7 @@ class AtlasSimbiconWidget : public dart::gui::osg::ImGuiWidget

void setGravity(float gravity);

dart::gui::osg::ImGuiViewer* mViewer;
::osg::ref_ptr<dart::gui::osg::ImGuiViewer> mViewer;

AtlasSimbiconWorldNode* mNode;

Expand Down
22 changes: 11 additions & 11 deletions examples/osgExamples/osgAtlasSimbicon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,34 @@ int main()
= new AtlasSimbiconWorldNode(world, atlas);

// Create a Viewer and set it up with the WorldNode
dart::gui::osg::ImGuiViewer viewer;
viewer.addWorldNode(node);
osg::ref_ptr<dart::gui::osg::ImGuiViewer> viewer = new dart::gui::osg::ImGuiViewer();
viewer->addWorldNode(node);

// Add control widget for atlas
viewer.getImGuiHandler()->addWidget(
std::make_shared<AtlasSimbiconWidget>(&viewer, node.get()));
viewer->getImGuiHandler()->addWidget(
std::make_shared<AtlasSimbiconWidget>(viewer, node.get()));

// Pass in the custom event handler
viewer.addEventHandler(new AtlasSimbiconEventHandler(node));
viewer->addEventHandler(new AtlasSimbiconEventHandler(node));

// Set the dimensions for the window
viewer.setUpViewInWindow(0, 0, 1280, 960);
viewer->setUpViewInWindow(0, 0, 1280, 960);

// Set the window name
viewer.realize();
viewer->realize();
osgViewer::Viewer::Windows windows;
viewer.getWindows(windows);
viewer->getWindows(windows);
windows.front()->setWindowName("Atlas Simbicon");

// Adjust the viewpoint of the Viewer
viewer.getCameraManipulator()->setHomePosition(
viewer->getCameraManipulator()->setHomePosition(
::osg::Vec3d( 5.14, 3.28, 6.28)*2.0,
::osg::Vec3d( 1.00, 0.00, 0.00),
::osg::Vec3d( 0.00, 0.1, 0.00));
// We need to re-dirty the CameraManipulator by passing it into the viewer
// again, so that the viewer knows to update its HomePosition setting
viewer.setCameraManipulator(viewer.getCameraManipulator());
viewer->setCameraManipulator(viewer->getCameraManipulator());

// Begin running the application loop
viewer.run();
viewer->run();
}
25 changes: 13 additions & 12 deletions examples/osgExamples/osgBoxStacking/osgBoxStacking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ class TestWidget : public dart::gui::osg::ImGuiWidget
void render() override
{
ImGui::SetNextWindowPos(ImVec2(10, 20));
ImGui::SetNextWindowSize(ImVec2(240, 320));
ImGui::SetNextWindowBgAlpha(0.5f);
if (!ImGui::Begin(
"Box Stacking",
nullptr,
ImVec2(240, 320),
0.5f,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_MenuBar
| ImGuiWindowFlags_HorizontalScrollbar))
{
Expand Down Expand Up @@ -396,7 +396,7 @@ class TestWidget : public dart::gui::osg::ImGuiWidget
mWorld->setGravity(Eigen::Vector3d::Zero());
}

dart::gui::osg::ImGuiViewer* mViewer;
::osg::ref_ptr<dart::gui::osg::ImGuiViewer> mViewer;
dart::simulation::WorldPtr mWorld;
bool mGuiGravity;
bool mGravity;
Expand All @@ -418,31 +418,32 @@ int main()
osg::ref_ptr<CustomWorldNode> node = new CustomWorldNode(world);

// Create a Viewer and set it up with the WorldNode
dart::gui::osg::ImGuiViewer viewer;
viewer.addWorldNode(node);
osg::ref_ptr<dart::gui::osg::ImGuiViewer> viewer
= new dart::gui::osg::ImGuiViewer();
viewer->addWorldNode(node);

// Add control widget for atlas
viewer.getImGuiHandler()->addWidget(
std::make_shared<TestWidget>(&viewer, world));
viewer->getImGuiHandler()->addWidget(
std::make_shared<TestWidget>(viewer, world));

// Pass in the custom event handler
viewer.addEventHandler(new CustomEventHandler);
viewer->addEventHandler(new CustomEventHandler);

// Set up the window to be 800x640
viewer.setUpViewInWindow(0, 0, 800, 640);
viewer->setUpViewInWindow(0, 0, 800, 640);

// Adjust the viewpoint of the Viewer
viewer.getCameraManipulator()->setHomePosition(
viewer->getCameraManipulator()->setHomePosition(
::osg::Vec3(12.00f, 12.00f, 9.00f),
::osg::Vec3(0.00f, 0.00f, 2.00f),
::osg::Vec3(0.00f, 0.00f, 1.00f));

// We need to re-dirty the CameraManipulator by passing it into the viewer
// again, so that the viewer knows to update its HomePosition setting
viewer.setCameraManipulator(viewer.getCameraManipulator());
viewer->setCameraManipulator(viewer->getCameraManipulator());

// Begin running the application loop
viewer.run();
viewer->run();

return 0;
}
27 changes: 15 additions & 12 deletions examples/osgExamples/osgImGui/osgImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ class TestWidget : public dart::gui::osg::ImGuiWidget
void render() override
{
ImGui::SetNextWindowPos(ImVec2(10,20));
if (!ImGui::Begin("Tinkertoy Control", nullptr, ImVec2(240, 320), 0.5f,
ImGui::SetNextWindowSize(ImVec2(240, 320));
ImGui::SetNextWindowBgAlpha(0.5f);
if (!ImGui::Begin("Tinkertoy Control", nullptr,
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_HorizontalScrollbar))
Expand Down Expand Up @@ -260,7 +262,7 @@ class TestWidget : public dart::gui::osg::ImGuiWidget
mWorld->setGravity(Eigen::Vector3d::Zero());
}

dart::gui::osg::ImGuiViewer* mViewer;
osg::ref_ptr<dart::gui::osg::ImGuiViewer> mViewer;
dart::simulation::WorldPtr mWorld;
bool mGuiGravity;
bool mGravity;
Expand All @@ -282,31 +284,32 @@ int main()
osg::ref_ptr<CustomWorldNode> node = new CustomWorldNode(world);

// Create a Viewer and set it up with the WorldNode
dart::gui::osg::ImGuiViewer viewer;
viewer.addWorldNode(node);
osg::ref_ptr<dart::gui::osg::ImGuiViewer> viewer
= new dart::gui::osg::ImGuiViewer();
viewer->addWorldNode(node);

// Add control widget for atlas
viewer.getImGuiHandler()->addWidget(
std::make_shared<TestWidget>(&viewer, world));
viewer->getImGuiHandler()->addWidget(
std::make_shared<TestWidget>(viewer, world));

// Active the drag-and-drop feature for the target
viewer.enableDragAndDrop(target.get());
viewer->enableDragAndDrop(target.get());

// Pass in the custom event handler
viewer.addEventHandler(new CustomEventHandler);
viewer->addEventHandler(new CustomEventHandler);

// Set up the window to be 640x480
viewer.setUpViewInWindow(0, 0, 640, 480);
viewer->setUpViewInWindow(0, 0, 640, 480);

// Adjust the viewpoint of the Viewer
viewer.getCameraManipulator()->setHomePosition(
viewer->getCameraManipulator()->setHomePosition(
::osg::Vec3( 2.57f, 3.14f, 1.64f),
::osg::Vec3( 0.00f, 0.00f, 0.00f),
::osg::Vec3(-0.24f, -0.25f, 0.94f));
// We need to re-dirty the CameraManipulator by passing it into the viewer
// again, so that the viewer knows to update its HomePosition setting
viewer.setCameraManipulator(viewer.getCameraManipulator());
viewer->setCameraManipulator(viewer->getCameraManipulator());

// Begin running the application loop
viewer.run();
viewer->run();
}
Loading