Skip to content

Commit

Permalink
[CollisionOBBCapsule] Fix Capsule destructor (sofa-framework#5147)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger authored Dec 10, 2024
1 parent 539b6be commit 37ab743
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(HEADER_FILES
)

set(SOURCE_FILES
CapsuleModel_test.cpp
OBB_test.cpp
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: [email protected] *
******************************************************************************/
#include <gtest/gtest.h>
#include <CollisionOBBCapsule/geometry/CapsuleModel.h>
#include <sofa/core/ObjectFactory.h>

TEST(CapsuleModel, creationFromFactory)
{
const auto entry = sofa::core::ObjectFactory::getInstance()->getEntry("CapsuleCollisionModel");
const auto creatorRigid = entry.creatorMap.at("Rigid3d");

sofa::core::objectmodel::BaseObjectDescription desc;
const auto object = creatorRigid->createInstance(nullptr, &desc);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace collisionobbcapsule::geometry
using namespace sofa::defaulttype;

int CapsuleCollisionModelClass = core::RegisterObject("Collision model which represents a set of Capsules")
.add< CapsuleCollisionModel<sofa::defaulttype::Vec3Types> >()
.add< CapsuleCollisionModel<sofa::defaulttype::Vec3Types> >()
.add< CapsuleCollisionModel<sofa::defaulttype::Rigid3Types> >()
;

template class COLLISIONOBBCAPSULE_API TCapsule<defaulttype::Vec3Types>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class CapsuleCollisionModel : public core::CollisionModel

CapsuleCollisionModel();
CapsuleCollisionModel(core::behavior::MechanicalState<TDataTypes>* mstate );

~CapsuleCollisionModel() override;
public:
void init() override;

Expand Down Expand Up @@ -153,11 +155,14 @@ class CapsuleCollisionModel : public core::CollisionModel
template<class T>
static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
{
if (dynamic_cast<core::behavior::MechanicalState<TDataTypes>*>(context->getMechanicalState()) == nullptr && context->getMechanicalState() != nullptr)
if (context)
{
arg->logError(std::string("No mechanical state with the datatype '") + DataTypes::Name() +
"' found in the context node.");
return false;
if (dynamic_cast<core::behavior::MechanicalState<TDataTypes>*>(context->getMechanicalState()) == nullptr && context->getMechanicalState() != nullptr)
{
arg->logError(std::string("No mechanical state with the datatype '") + DataTypes::Name() +
"' found in the context node.");
return false;
}
}

return BaseObject::canCreate(obj, context, arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ CapsuleCollisionModel<DataTypes>::CapsuleCollisionModel(core::behavior::Mechanic
enum_type = CAPSULE_TYPE;
}

template <class TDataTypes>
CapsuleCollisionModel<TDataTypes>::~CapsuleCollisionModel()
{}

template<class DataTypes>
void CapsuleCollisionModel<DataTypes>::resize(sofa::Size size)
{
Expand Down

0 comments on commit 37ab743

Please sign in to comment.