chore: memory cleanup fixes

This commit is contained in:
Almamu 2025-04-01 12:53:16 +02:00
parent 0dbd10440c
commit 35969a7a0a
4 changed files with 33 additions and 20 deletions

View File

@ -6,14 +6,14 @@
#include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"
#include "common.h"
WallpaperEngine::Application::CWallpaperApplication* appPointer;
WallpaperEngine::Application::CWallpaperApplication* app;
void signalhandler(int sig)
{
if (appPointer == nullptr)
if (app == nullptr)
return;
appPointer->signal (sig);
app->signal (sig);
}
void initLogging ()
@ -31,17 +31,20 @@ int main (int argc, char* argv[]) {
if (appContext.settings.general.onlyListProperties)
return 0;
WallpaperEngine::Application::CWallpaperApplication app (appContext, webBrowserContext);
appPointer = &app;
app = new WallpaperEngine::Application::CWallpaperApplication (appContext, webBrowserContext);
// attach signals to gracefully stop
std::signal (SIGINT, signalhandler);
std::signal (SIGTERM, signalhandler);
// show the wallpaper application
app.show ();
app->show ();
// remove signal handlers before destroying app
std::signal (SIGINT, SIG_DFL);
std::signal (SIGTERM, SIG_DFL);
delete app;
appPointer = nullptr;
return 0;
}

View File

@ -33,7 +33,14 @@ namespace WallpaperEngine::Application {
CWallpaperApplication::CWallpaperApplication (CApplicationContext& context,
WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext) :
m_context (context),
m_browserContext (browserContext) {
m_browserContext (browserContext),
m_audioContext (nullptr),
m_audioDriver (nullptr),
m_audioRecorder (nullptr),
m_inputContext (nullptr),
m_renderContext (nullptr),
m_videoDriver (nullptr),
m_fullScreenDetector (nullptr) {
this->loadBackgrounds ();
this->setupProperties ();
}
@ -398,11 +405,11 @@ void CWallpaperApplication::show () {
static time_t seconds;
static struct tm* timeinfo;
while (this->m_context.state.general.keepRunning && !m_videoDriver->closeRequested ()) {
while (this->m_context.state.general.keepRunning) {
// update g_Daytime
time (&seconds);
timeinfo = localtime (&seconds);
g_Daytime = ((timeinfo->tm_hour * 60) + timeinfo->tm_min) / (24.0 * 60.0);
g_Daytime = ((timeinfo->tm_hour * 60.0f) + timeinfo->tm_min) / (24.0f * 60.0f);
// keep track of the previous frame's time
g_TimeLast = g_Time;
@ -422,6 +429,11 @@ void CWallpaperApplication::show () {
// process driver events
m_videoDriver->dispatchEventQueue ();
if (m_videoDriver->closeRequested()) {
sLog.out ("Stop requested by driver");
this->m_context.state.general.keepRunning = false;
}
if (!this->m_context.settings.screenshot.take || m_videoDriver->getFrameCounter () < 5)
continue;
@ -429,10 +441,7 @@ void CWallpaperApplication::show () {
this->m_context.settings.screenshot.take = false;
}
// ensure this is updated as sometimes it might not come from a signal
this->m_context.state.general.keepRunning = false;
sLog.out ("Stop requested");
sLog.out ("Stopping");
SDL_Quit ();
}
@ -443,6 +452,7 @@ void CWallpaperApplication::update (Render::Drivers::Output::COutputViewport* vi
}
void CWallpaperApplication::signal (int signal) {
sLog.out ("Stop requested by signal ", signal);
this->m_context.state.general.keepRunning = false;
}

View File

@ -28,9 +28,9 @@ class CObject : public Helpers::CContextAware {
virtual void render () = 0;
CScene* getScene () const;
CContainer* getContainer () const;
int getId () const;
[[nodiscard]] CScene* getScene () const;
[[nodiscard]] CContainer* getContainer () const;
[[nodiscard]] int getId () const;
protected:
CObject (CScene* scene, std::string type, Core::CObject* object);

View File

@ -11,7 +11,7 @@ namespace WallpaperEngine::Render::Objects {
class CSound final : public CObject {
public:
CSound (CScene* scene, Core::Objects::CSound* sound);
~CSound ();
~CSound () override;
void render () override;
@ -21,7 +21,7 @@ class CSound final : public CObject {
void load ();
private:
std::vector<const void*> m_soundBuffer;
std::vector<const uint8_t*> m_soundBuffer;
std::vector<Audio::CAudioStream*> m_audioStreams;
Core::Objects::CSound* m_sound;