Updated the way module are initialized
It's safer and prevent a bug when initialisation fails Former-commit-id: a04f18e18f2d9db11ec595a9b8096c2792b39641
This commit is contained in:
parent
3f4b3aeef5
commit
fd958fd9ac
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ModuleName/ModuleName.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
|
|
@ -11,8 +12,11 @@
|
|||
|
||||
bool NzModuleName::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzCore::Initialize())
|
||||
|
|
@ -21,10 +25,14 @@ bool NzModuleName::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation du module
|
||||
NzCallOnExit onExit(NzModuleName::Uninitialize);
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
NazaraNotice("Initialized: ModuleName module");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <Nazara/Audio/Enums.hpp>
|
||||
#include <Nazara/Audio/OpenAL.hpp>
|
||||
#include <Nazara/Audio/Loaders/sndfile.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
|
|
@ -84,24 +85,28 @@ float NzAudio::GetSpeedOfSound()
|
|||
|
||||
bool NzAudio::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzCore::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize core module");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation du module
|
||||
NzCallOnExit onExit(NzAudio::Uninitialize);
|
||||
|
||||
// Initialisation d'OpenGL
|
||||
if (!NzOpenAL::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize OpenAL");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -111,8 +116,9 @@ bool NzAudio::Initialize()
|
|||
// Loaders
|
||||
NzLoaders_sndfile_Register();
|
||||
|
||||
NazaraNotice("Initialized: Audio module");
|
||||
onExit.Reset();
|
||||
|
||||
NazaraNotice("Initialized: Audio module");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,15 @@
|
|||
|
||||
bool NzCore::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
NazaraNotice("Initialized: Core");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Graphics.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
|
|
@ -16,19 +17,23 @@
|
|||
|
||||
bool NzGraphics::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzRenderer::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Renderer module");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation du module
|
||||
NzCallOnExit onExit(NzGraphics::Uninitialize);
|
||||
|
||||
// Loaders
|
||||
NzLoaders_OBJ_Register();
|
||||
|
|
@ -42,8 +47,9 @@ bool NzGraphics::Initialize()
|
|||
if (NzDeferredRenderTechnique::IsSupported())
|
||||
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_DeferredShading), 20, []() -> NzAbstractRenderTechnique* { return new NzDeferredRenderTechnique; });
|
||||
|
||||
NazaraNotice("Initialized: Graphics module");
|
||||
onExit.Reset();
|
||||
|
||||
NazaraNotice("Initialized: Graphics module");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,11 @@
|
|||
|
||||
bool NzLua::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzCore::Initialize())
|
||||
|
|
@ -21,10 +24,11 @@ bool NzLua::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation du module
|
||||
|
||||
NazaraNotice("Initialized: Lua module");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,11 @@
|
|||
|
||||
bool NzNoise::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzCore::Initialize())
|
||||
|
|
@ -23,10 +26,11 @@ bool NzNoise::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation du module
|
||||
|
||||
NazaraNotice("Initialized: Noise module");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,22 +17,24 @@ unsigned int NzPhysics::GetMemoryUsed()
|
|||
|
||||
bool NzPhysics::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzCore::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize core module");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation du module
|
||||
|
||||
NazaraNotice("Initialized: Physics module");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
|
|
@ -634,24 +635,28 @@ bool NzRenderer::HasCapability(nzRendererCap capability)
|
|||
|
||||
bool NzRenderer::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzUtility::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Utility module");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation du module
|
||||
NzCallOnExit onExit(NzRenderer::Uninitialize);
|
||||
|
||||
// Initialisation d'OpenGL
|
||||
if (!NzOpenGL::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize OpenGL");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -751,8 +756,6 @@ bool NzRenderer::Initialize()
|
|||
if (!s_fullscreenQuadBuffer.Fill(vertices, 0, 4))
|
||||
{
|
||||
NazaraError("Failed to fill fullscreen quad buffer");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -773,32 +776,27 @@ bool NzRenderer::Initialize()
|
|||
if (!NzMaterial::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize materials");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NzShaderProgramManager::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize shader program manager");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NzTextureSampler::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize texture sampler");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Loaders
|
||||
NzLoaders_Texture_Register();
|
||||
|
||||
NazaraNotice("Initialized: Renderer module");
|
||||
onExit.Reset();
|
||||
|
||||
NazaraNotice("Initialized: Renderer module");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
|
|
@ -23,58 +24,53 @@
|
|||
|
||||
bool NzUtility::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzCore::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize core module");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation du module
|
||||
#if NAZARA_UTILITY_MULTITHREADED_SKINNING
|
||||
if (!NzTaskScheduler::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize task scheduler");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
NzCallOnExit onExit(NzUtility::Uninitialize);
|
||||
|
||||
if (!NzBuffer::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize buffers");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NzPixelFormat::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize pixel formats");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#if NAZARA_UTILITY_MULTITHREADED_SKINNING
|
||||
if (!NzTaskScheduler::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize task scheduler");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!NzVertexDeclaration::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize vertex declarations");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NzWindow::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize window's system");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -96,8 +92,9 @@ bool NzUtility::Initialize()
|
|||
// Image
|
||||
NzLoaders_PCX_Register(); // Loader de fichiers .pcx (1, 4, 8, 24 bits)
|
||||
|
||||
NazaraNotice("Initialized: Utility module");
|
||||
onExit.Reset();
|
||||
|
||||
NazaraNotice("Initialized: Utility module");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue