Skip to content

Commit cd4e406

Browse files
committed
Reverted OpenSim::Controller fix to use constructProperties (#3247)
1 parent bd8b11b commit cd4e406

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

OpenSim/Simulation/Control/Controller.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ Controller::Controller() :
4949
_numControls{0},
5050
_actuatorSet{}
5151
{
52-
setAuthors("Ajay Seth, Frank Anderson, Chand John, Samuel Hamner");
53-
constructProperty_enabled(true);
54-
constructProperty_actuator_list();
55-
_actuatorSet.setMemoryOwner(false);
52+
constructProperties();
5653
}
5754

5855
Controller::Controller(Controller const& src) :
@@ -62,11 +59,16 @@ Controller::Controller(Controller const& src) :
6259
_numControls{src._numControls},
6360
_actuatorSet{}
6461
{
62+
// care: the reason this custom copy constructor exists is to prevent
63+
// a memory leak (#3247)
6564
_actuatorSet.setMemoryOwner(false);
6665
}
6766

6867
Controller& Controller::operator=(Controller const& src)
6968
{
69+
// care: the reason this custom copy assignment exists is to prevent
70+
// a memory leak (#3247)
71+
7072
if (&src != this)
7173
{
7274
static_cast<ModelComponent&>(*this) = static_cast<ModelComponent const&>(src);
@@ -86,6 +88,17 @@ Controller::~Controller() noexcept = default;
8688
//_____________________________________________________________________________
8789
//_____________________________________________________________________________
8890

91+
/**
92+
* Connect properties to local pointers.
93+
*/
94+
void Controller::constructProperties()
95+
{
96+
setAuthors("Ajay Seth, Frank Anderson, Chand John, Samuel Hamner");
97+
constructProperty_enabled(true);
98+
constructProperty_actuator_list();
99+
_actuatorSet.setMemoryOwner(false);
100+
}
101+
89102
void Controller::updateFromXMLNode(SimTK::Xml::Element& node,
90103
int versionNumber) {
91104
if(versionNumber < XMLDocument::getLatestVersion()) {

OpenSim/Simulation/Control/Controller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(Controller, ModelComponent);
146146
// the (sub)set of Model actuators that this controller controls */
147147
Set<const Actuator> _actuatorSet;
148148

149+
// construct and initialize properties
150+
void constructProperties();
151+
149152
//=============================================================================
150153
}; // END of class Controller
151154

0 commit comments

Comments
 (0)