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