Patch - Adds component shutdown functionality - V13.6.1
Implements a shutdown mechanism for components and entities, ensuring proper resource release and preventing memory leaks. This change introduces a virtual `Shutdown` method to the `Component` class, allowing derived components to release specific resources when they are removed from an entity or when the entity is destroyed. The `Entity` class now calls the `Shutdown` method on all its components during its own release process. The `EntityManager` now calls the `release()` method when destroying an entity. This enhancement ensures that resources, such as FMOD sound objects and channels in the `AudioComponent`, are properly released, preventing potential resource leaks and improving the stability of the engine.
This commit is contained in:
@@ -30,6 +30,27 @@ public:
|
||||
// Ne pas lib<69>rer m_system ici car il peut <20>tre partag<61>
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the audio component by releasing the sound and channel.
|
||||
* This method is called when the component is removed from an entity or when the entity is destroyed.
|
||||
*/
|
||||
void Shutdown() override {
|
||||
if (m_channel) {
|
||||
bool isPlaying = false;
|
||||
m_channel->isPlaying(&isPlaying);
|
||||
if (isPlaying) {
|
||||
m_channel->stop();
|
||||
}
|
||||
m_channel = nullptr;
|
||||
}
|
||||
if (m_sound) {
|
||||
m_sound->release();
|
||||
m_sound = nullptr;
|
||||
}
|
||||
m_system = nullptr; // Ne pas lib<69>rer m_system ici car il peut <20>tre partag<61>
|
||||
m_camera = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the audio component by setting up the FMOD system and camera from the parent entity.
|
||||
* This method is called when the component is added to an entity.
|
||||
|
||||
Reference in New Issue
Block a user