Default (XML) electrical system: fix leaks
Ensure shutdown of the electrical system actually cleans up components. Fixes some leaks and dangling properties on reset.
This commit is contained in:
parent
b4df97beb6
commit
f8fcc8ff5d
2 changed files with 26 additions and 2 deletions
|
@ -359,7 +359,9 @@ FGElectricalSystem::FGElectricalSystem ( SGPropertyNode *node ) :
|
|||
}
|
||||
|
||||
|
||||
FGElectricalSystem::~FGElectricalSystem () {
|
||||
FGElectricalSystem::~FGElectricalSystem()
|
||||
{
|
||||
SG_LOG(SG_SYSTEMS, SG_INFO, "Destroying elec system");
|
||||
}
|
||||
|
||||
|
||||
|
@ -426,8 +428,27 @@ void FGElectricalSystem::bind ()
|
|||
void FGElectricalSystem::unbind ()
|
||||
{
|
||||
_serviceable_node.reset();
|
||||
_volts_out.reset();
|
||||
_amps_out.reset();
|
||||
}
|
||||
|
||||
void FGElectricalSystem::deleteComponents(comp_list& comps)
|
||||
{
|
||||
std::for_each(comps.begin(), comps.end(),
|
||||
[](FGElectricalComponent* comp) {
|
||||
delete comp;
|
||||
});
|
||||
|
||||
comps.clear();
|
||||
}
|
||||
|
||||
void FGElectricalSystem::shutdown()
|
||||
{
|
||||
deleteComponents(suppliers);
|
||||
deleteComponents(buses);
|
||||
deleteComponents(outputs);
|
||||
deleteComponents(connectors);
|
||||
}
|
||||
|
||||
void FGElectricalSystem::update (double dt)
|
||||
{
|
||||
|
|
|
@ -66,7 +66,7 @@ protected:
|
|||
|
||||
public:
|
||||
FGElectricalComponent();
|
||||
virtual ~FGElectricalComponent() {}
|
||||
virtual ~FGElectricalComponent() = default;
|
||||
|
||||
inline const std::string& get_name() { return name; }
|
||||
|
||||
|
@ -222,6 +222,7 @@ public:
|
|||
// Subsystem API.
|
||||
void bind() override;
|
||||
void init() override;
|
||||
void shutdown() override;
|
||||
void unbind() override;
|
||||
void update(double dt) override;
|
||||
|
||||
|
@ -238,6 +239,8 @@ protected:
|
|||
typedef vector<FGElectricalComponent *> comp_list;
|
||||
|
||||
private:
|
||||
void deleteComponents(comp_list& comps);
|
||||
|
||||
std::string name;
|
||||
int num;
|
||||
std::string path;
|
||||
|
|
Loading…
Add table
Reference in a new issue