mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
chore: memory cleanup fixes
This commit is contained in:
parent
0dbd10440c
commit
35969a7a0a
19
main.cpp
19
main.cpp
@ -6,14 +6,14 @@
|
|||||||
#include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"
|
#include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
WallpaperEngine::Application::CWallpaperApplication* appPointer;
|
WallpaperEngine::Application::CWallpaperApplication* app;
|
||||||
|
|
||||||
void signalhandler(int sig)
|
void signalhandler(int sig)
|
||||||
{
|
{
|
||||||
if (appPointer == nullptr)
|
if (app == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
appPointer->signal (sig);
|
app->signal (sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initLogging ()
|
void initLogging ()
|
||||||
@ -31,17 +31,20 @@ int main (int argc, char* argv[]) {
|
|||||||
if (appContext.settings.general.onlyListProperties)
|
if (appContext.settings.general.onlyListProperties)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
WallpaperEngine::Application::CWallpaperApplication app (appContext, webBrowserContext);
|
app = new WallpaperEngine::Application::CWallpaperApplication (appContext, webBrowserContext);
|
||||||
|
|
||||||
appPointer = &app;
|
|
||||||
|
|
||||||
// attach signals to gracefully stop
|
// attach signals to gracefully stop
|
||||||
std::signal (SIGINT, signalhandler);
|
std::signal (SIGINT, signalhandler);
|
||||||
std::signal (SIGTERM, signalhandler);
|
std::signal (SIGTERM, signalhandler);
|
||||||
|
|
||||||
// show the wallpaper application
|
// 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;
|
return 0;
|
||||||
}
|
}
|
@ -33,7 +33,14 @@ namespace WallpaperEngine::Application {
|
|||||||
CWallpaperApplication::CWallpaperApplication (CApplicationContext& context,
|
CWallpaperApplication::CWallpaperApplication (CApplicationContext& context,
|
||||||
WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext) :
|
WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext) :
|
||||||
m_context (context),
|
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->loadBackgrounds ();
|
||||||
this->setupProperties ();
|
this->setupProperties ();
|
||||||
}
|
}
|
||||||
@ -398,11 +405,11 @@ void CWallpaperApplication::show () {
|
|||||||
static time_t seconds;
|
static time_t seconds;
|
||||||
static struct tm* timeinfo;
|
static struct tm* timeinfo;
|
||||||
|
|
||||||
while (this->m_context.state.general.keepRunning && !m_videoDriver->closeRequested ()) {
|
while (this->m_context.state.general.keepRunning) {
|
||||||
// update g_Daytime
|
// update g_Daytime
|
||||||
time (&seconds);
|
time (&seconds);
|
||||||
timeinfo = localtime (&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
|
// keep track of the previous frame's time
|
||||||
g_TimeLast = g_Time;
|
g_TimeLast = g_Time;
|
||||||
@ -422,6 +429,11 @@ void CWallpaperApplication::show () {
|
|||||||
// process driver events
|
// process driver events
|
||||||
m_videoDriver->dispatchEventQueue ();
|
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)
|
if (!this->m_context.settings.screenshot.take || m_videoDriver->getFrameCounter () < 5)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -429,10 +441,7 @@ void CWallpaperApplication::show () {
|
|||||||
this->m_context.settings.screenshot.take = false;
|
this->m_context.settings.screenshot.take = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure this is updated as sometimes it might not come from a signal
|
sLog.out ("Stopping");
|
||||||
this->m_context.state.general.keepRunning = false;
|
|
||||||
|
|
||||||
sLog.out ("Stop requested");
|
|
||||||
|
|
||||||
SDL_Quit ();
|
SDL_Quit ();
|
||||||
}
|
}
|
||||||
@ -443,6 +452,7 @@ void CWallpaperApplication::update (Render::Drivers::Output::COutputViewport* vi
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::signal (int signal) {
|
void CWallpaperApplication::signal (int signal) {
|
||||||
|
sLog.out ("Stop requested by signal ", signal);
|
||||||
this->m_context.state.general.keepRunning = false;
|
this->m_context.state.general.keepRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ class CObject : public Helpers::CContextAware {
|
|||||||
|
|
||||||
virtual void render () = 0;
|
virtual void render () = 0;
|
||||||
|
|
||||||
CScene* getScene () const;
|
[[nodiscard]] CScene* getScene () const;
|
||||||
CContainer* getContainer () const;
|
[[nodiscard]] CContainer* getContainer () const;
|
||||||
int getId () const;
|
[[nodiscard]] int getId () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CObject (CScene* scene, std::string type, Core::CObject* object);
|
CObject (CScene* scene, std::string type, Core::CObject* object);
|
||||||
|
@ -11,7 +11,7 @@ namespace WallpaperEngine::Render::Objects {
|
|||||||
class CSound final : public CObject {
|
class CSound final : public CObject {
|
||||||
public:
|
public:
|
||||||
CSound (CScene* scene, Core::Objects::CSound* sound);
|
CSound (CScene* scene, Core::Objects::CSound* sound);
|
||||||
~CSound ();
|
~CSound () override;
|
||||||
|
|
||||||
void render () override;
|
void render () override;
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ class CSound final : public CObject {
|
|||||||
void load ();
|
void load ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<const void*> m_soundBuffer;
|
std::vector<const uint8_t*> m_soundBuffer;
|
||||||
std::vector<Audio::CAudioStream*> m_audioStreams;
|
std::vector<Audio::CAudioStream*> m_audioStreams;
|
||||||
|
|
||||||
Core::Objects::CSound* m_sound;
|
Core::Objects::CSound* m_sound;
|
||||||
|
Loading…
Reference in New Issue
Block a user