Improve memory safety

Fixed a case where after the splash screen was over the RenderTargets & Texture created in it weren't deleted.
This commit is contained in:
2025-01-17 20:13:27 -05:00
parent 5a48438e11
commit 0ee0dca397
3 changed files with 21 additions and 13 deletions

View File

@@ -14,6 +14,8 @@ namespace CaveGame::Client
{
public:
Scene();
virtual ~Scene() = default;
/// This function is called by the SceneManager when a scene is changed.
/// @note Make sure to call this base when overriding in derived Scene classes.
virtual void Load();

View File

@@ -11,23 +11,11 @@ namespace CaveGame::Client
/// The splash screen is responsible for displaying the Redacted Software Logo and then showing the loading bar.
class Splash : public Scene
{
public:
Splash();
//~Splash();
void Draw() override;
void Update(float elapsed) override;
void Load() override;
void Unload() override;
//void PassFont(JGL::Font passed);
bool SplashComplete() const;
private:
float splash_timer = 1.5f;
float load_percent = 0.f;
JGL::Texture* splash; // TODO: RAII on this
//JGL::Font font; // TODO: RAII on this
float increment = 0;
std::array<JGL::RenderTarget*, 16> column_textures{};
@@ -41,5 +29,16 @@ namespace CaveGame::Client
void DrawMatrix();
void DrawProgressBar();
public:
Splash();
~Splash() override;
void Draw() override;
void Update(float elapsed) override;
void Load() override;
void Unload() override;
//void PassFont(JGL::Font passed);
[[nodiscard]] bool SplashComplete() const;
};
}

View File

@@ -135,10 +135,17 @@ void CaveGame::Client::Splash::Load() {
}
void CaveGame::Client::Splash::Unload() {
Scene::Unload();
for (auto* r : column_textures)
delete r;
delete splash;
Scene::Unload();
}
bool CaveGame::Client::Splash::SplashComplete() const {
return splash_timer < 0;
}
CaveGame::Client::Splash::~Splash() {
Splash::Unload();
}