From 404d2dbeb1d8cb2e9a6748038bb48160f1aac5a2 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Sun, 7 Feb 2021 13:38:29 +0100 Subject: [PATCH] Fix segfault in CApp UT I moved m_engine creation to the constructor. However, it is not complete until after calling m_engine->Create(). The UT segfault because the pointer is not null and destructor calls m_engine->Destroy() on an incomplete object. (Yes, UTs test incomplete SUT.) So I moved back the m_engine creation to CApp::Create() but before the SDL initialization as m_engine holds the flag for vsync. --- src/app/app.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 8e43780a..1e4515ed 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -112,7 +112,6 @@ struct ApplicationPrivate CApplication::CApplication(CSystemUtils* systemUtils) : m_systemUtils(systemUtils), m_private(MakeUnique()), - m_engine(MakeUnique(this, m_systemUtils)), m_configFile(MakeUnique()), m_input(MakeUnique()), m_pathManager(MakeUnique(systemUtils)), @@ -550,6 +549,8 @@ bool CApplication::Create() /* SDL initialization sequence */ + // Creating the m_engine now because it holds the vsync flag + m_engine = MakeUnique(this, m_systemUtils); Uint32 initFlags = SDL_INIT_VIDEO | SDL_INIT_TIMER;