Skip to content

Commit

Permalink
correctly clear windows on exit to avoid panda assert
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Dec 13, 2024
1 parent 040b88a commit 4559f93
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 2 deletions.
12 changes: 12 additions & 0 deletions modules/ar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,15 @@ vp_glob_module_sources()

vp_module_include_directories(${opt_incs} SYSTEM ${opt_system_incs})
vp_create_module(${opt_libs})


set(opt_test_incs "")
set(opt_test_libs "")

if(WITH_CATCH2)
# catch2 is private
list(APPEND opt_test_incs ${CATCH2_INCLUDE_DIRS})
list(APPEND opt_test_libs ${CATCH2_LIBRARIES})
endif()

vp_add_tests(DEPENDS_ON visp_core PRIVATE_INCLUDE_DIRS ${opt_test_incs} PRIVATE_LIBRARIES ${opt_test_libs})
17 changes: 15 additions & 2 deletions modules/ar/include/visp3/ar/vpPanda3DBaseRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,24 @@ class VISP_EXPORT vpPanda3DBaseRenderer
{
public:
vpPanda3DBaseRenderer(const std::string &rendererName)
: m_name(rendererName), m_renderOrder(-100), m_window(nullptr), m_camera(nullptr)
: m_name(rendererName), m_renderOrder(-100), m_window(nullptr), m_camera(nullptr), m_isWindowOwner(false)
{
setVerticalSyncEnabled(false);
}

virtual ~vpPanda3DBaseRenderer() = default;
virtual ~vpPanda3DBaseRenderer()
{
if (m_window != nullptr) {
for (GraphicsOutput *buffer: m_buffers) {
buffer->get_engine()->remove_window(buffer);
}
}
if (m_isWindowOwner) {
framework.close_window(m_window);
}

m_window = nullptr;
}

/**
* @brief Initialize the whole Panda3D framework. Create a new PandaFramework object and a new window.
Expand Down Expand Up @@ -278,6 +290,7 @@ class VISP_EXPORT vpPanda3DBaseRenderer
PointerTo<Camera> m_camera;
NodePath m_cameraPath; //! NodePath of the camera
std::vector<GraphicsOutput *> m_buffers; //! Set of buffers that this renderer uses. This storage contains weak refs to those buffers and should not deallocate them.
bool m_isWindowOwner; // Whether this panda subrenderer is the "owner" of the window framework and should close all associated windows when getting destroyed
};

END_VISP_NAMESPACE
Expand Down
4 changes: 4 additions & 0 deletions modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void vpPanda3DBaseRenderer::initFramework()
framework.open_framework();
}

m_isWindowOwner = true;

WindowProperties winProps;
winProps.set_size(LVecBase2i(m_renderParameters.getImageWidth(), m_renderParameters.getImageHeight()));
int flags = GraphicsPipe::BF_refuse_window;
Expand All @@ -83,6 +85,7 @@ void vpPanda3DBaseRenderer::initFramework()

void vpPanda3DBaseRenderer::initFromParent(PointerTo<WindowFramework> window)
{
m_isWindowOwner = false;
m_window = window;
setupScene();
setupCamera();
Expand All @@ -91,6 +94,7 @@ void vpPanda3DBaseRenderer::initFromParent(PointerTo<WindowFramework> window)

void vpPanda3DBaseRenderer::initFromParent(const vpPanda3DBaseRenderer &renderer)
{
m_isWindowOwner = false;
initFromParent(renderer.m_window);
}

Expand Down
1 change: 1 addition & 0 deletions modules/ar/src/panda3d-simulator/vpPanda3DRendererSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void vpPanda3DRendererSet::initFramework()
frameworkIsOpen = true;
framework.open_framework();
}
m_isWindowOwner = true;

WindowProperties winProps;
winProps.set_size(LVecBase2i(m_renderParameters.getImageWidth(), m_renderParameters.getImageHeight()));
Expand Down
89 changes: 89 additions & 0 deletions modules/ar/test/catchPanda.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Test vpCameraParameters JSON parse / save.
*/

/*!
\example catchJsonCamera.cpp
Test saving and parsing JSON configuration for vpCameraParameters.
*/

#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpIoTools.h>

#if defined(VISP_HAVE_PANDA3D) && defined(VISP_HAVE_CATCH2)
#include <visp3/ar/vpPanda3DBaseRenderer.h>
#include <visp3/ar/vpPanda3DRGBRenderer.h>
#include <visp3/ar/vpPanda3DGeometryRenderer.h>
#include <visp3/core/vpCameraParameters.h>
#include <catch_amalgamated.hpp>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

#include <random>

SCENARIO("Instanciating multiple Panda3D renderers", "[Panda3D]")
{
GIVEN("A single renderer")
{
vpCameraParameters cam(600, 600, 160, 120);
vpPanda3DRenderParameters renderParams(cam, 240, 320, 0.001, 1.0);
vpPanda3DGeometryRenderer r1(vpPanda3DGeometryRenderer::CAMERA_NORMALS);
r1.setRenderParameters(renderParams);
r1.initFramework();

WHEN("Creating another, uncoupled renderer")
{
// vpPanda3DGeometryRenderer r2(vpPanda3DGeometryRenderer::CAMERA_NORMALS);
// r2.setRenderParameters(renderParams);
// r2.initFramework();

}
}
}

int main(int argc, char *argv[])
{
Catch::Session session; // There must be exactly one instance
session.applyCommandLine(argc, argv);

int numFailed = session.run();
return numFailed;
}

#else

int main() { return EXIT_SUCCESS; }

#endif

0 comments on commit 4559f93

Please sign in to comment.