Skip to content

Commit 37ab743

Browse files
authored
[CollisionOBBCapsule] Fix Capsule destructor (#5147)
1 parent 539b6be commit 37ab743

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

applications/plugins/CollisionOBBCapsule/CollisionOBBCapsule_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(HEADER_FILES
77
)
88

99
set(SOURCE_FILES
10+
CapsuleModel_test.cpp
1011
OBB_test.cpp
1112
)
1213

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Authors: The SOFA Team and external contributors (see Authors.txt) *
19+
* *
20+
* Contact information: contact@sofa-framework.org *
21+
******************************************************************************/
22+
#include <gtest/gtest.h>
23+
#include <CollisionOBBCapsule/geometry/CapsuleModel.h>
24+
#include <sofa/core/ObjectFactory.h>
25+
26+
TEST(CapsuleModel, creationFromFactory)
27+
{
28+
const auto entry = sofa::core::ObjectFactory::getInstance()->getEntry("CapsuleCollisionModel");
29+
const auto creatorRigid = entry.creatorMap.at("Rigid3d");
30+
31+
sofa::core::objectmodel::BaseObjectDescription desc;
32+
const auto object = creatorRigid->createInstance(nullptr, &desc);
33+
}

applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace collisionobbcapsule::geometry
2929
using namespace sofa::defaulttype;
3030

3131
int CapsuleCollisionModelClass = core::RegisterObject("Collision model which represents a set of Capsules")
32-
.add< CapsuleCollisionModel<sofa::defaulttype::Vec3Types> >()
32+
.add< CapsuleCollisionModel<sofa::defaulttype::Vec3Types> >()
33+
.add< CapsuleCollisionModel<sofa::defaulttype::Rigid3Types> >()
3334
;
3435

3536
template class COLLISIONOBBCAPSULE_API TCapsule<defaulttype::Vec3Types>;

applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class CapsuleCollisionModel : public core::CollisionModel
103103

104104
CapsuleCollisionModel();
105105
CapsuleCollisionModel(core::behavior::MechanicalState<TDataTypes>* mstate );
106+
107+
~CapsuleCollisionModel() override;
106108
public:
107109
void init() override;
108110

@@ -153,11 +155,14 @@ class CapsuleCollisionModel : public core::CollisionModel
153155
template<class T>
154156
static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
155157
{
156-
if (dynamic_cast<core::behavior::MechanicalState<TDataTypes>*>(context->getMechanicalState()) == nullptr && context->getMechanicalState() != nullptr)
158+
if (context)
157159
{
158-
arg->logError(std::string("No mechanical state with the datatype '") + DataTypes::Name() +
159-
"' found in the context node.");
160-
return false;
160+
if (dynamic_cast<core::behavior::MechanicalState<TDataTypes>*>(context->getMechanicalState()) == nullptr && context->getMechanicalState() != nullptr)
161+
{
162+
arg->logError(std::string("No mechanical state with the datatype '") + DataTypes::Name() +
163+
"' found in the context node.");
164+
return false;
165+
}
161166
}
162167

163168
return BaseObject::canCreate(obj, context, arg);

applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.inl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ CapsuleCollisionModel<DataTypes>::CapsuleCollisionModel(core::behavior::Mechanic
4747
enum_type = CAPSULE_TYPE;
4848
}
4949

50+
template <class TDataTypes>
51+
CapsuleCollisionModel<TDataTypes>::~CapsuleCollisionModel()
52+
{}
53+
5054
template<class DataTypes>
5155
void CapsuleCollisionModel<DataTypes>::resize(sofa::Size size)
5256
{

0 commit comments

Comments
 (0)