Fixed module initialisation failure bug

If a module initialisation failed, then it resources may or may not be
freed.
This is fixed.


Former-commit-id: 029e0844e392685a31b3afc02c5bf772e015a372
This commit is contained in:
Lynix 2012-12-25 01:56:49 +01:00
parent dc3cfa40ec
commit 1a4400facf
6 changed files with 37 additions and 10 deletions

View File

@ -18,6 +18,8 @@ bool Nz3D::Initialize()
if (!NzRenderer::Initialize())
{
NazaraError("Failed to initialize renderer module");
Uninitialize();
return false;
}

View File

@ -108,6 +108,8 @@ bool NzAudio::Initialize()
if (!NzCore::Initialize())
{
NazaraError("Failed to initialize core module");
Uninitialize();
return false;
}
@ -116,6 +118,8 @@ bool NzAudio::Initialize()
if (!device)
{
NazaraError("Failed to open default device");
Uninitialize();
return false;
}
@ -124,17 +128,16 @@ bool NzAudio::Initialize()
if (!context)
{
NazaraError("Failed to create context");
Uninitialize();
alcCloseDevice(device);
return false;
}
if (!alcMakeContextCurrent(context))
{
NazaraError("Failed to activate context");
Uninitialize();
alcDestroyContext(context);
alcCloseDevice(device);
return false;
}
@ -269,12 +272,18 @@ void NzAudio::Uninitialize()
NzLoaders_sndfile_Unregister();
// Libération d'OpenAL
alcMakeContextCurrent(nullptr);
alcDestroyContext(context);
if (device)
{
if (context)
{
alcMakeContextCurrent(nullptr);
alcDestroyContext(context);
}
if (!alcCloseDevice(device))
// Nous n'avons pas pu fermer le device, ce qui signifie qu'il est en cours d'utilisation
NazaraWarning("Failed to close device");
if (!alcCloseDevice(device))
// Nous n'avons pas pu fermer le device, ce qui signifie qu'il est en cours d'utilisation
NazaraWarning("Failed to close device");
}
NazaraNotice("Uninitialized: Audio module");

View File

@ -22,6 +22,8 @@ bool NzCore::Initialize(bool initializeHardwareInfo, bool initializeTaskSchedule
if (initializeTaskScheduler && !NzTaskScheduler::Initialize())
{
NazaraError("Failed to initialize task scheduler");
Uninitialize();
return false;
}

View File

@ -18,6 +18,8 @@ bool NzNoise::Initialize()
if (!NzCore::Initialize())
{
NazaraError("Failed to initialize core module");
Uninitialize();
return false;
}

View File

@ -466,7 +466,13 @@ bool NzRenderer::Initialize(bool initializeDebugDrawer)
if (initializeDebugDrawer && !NzDebugDrawer::Initialize())
NazaraWarning("Failed to initialize debug drawer"); // Non-critique
NzTextureSampler::Initialize();
if (!NzTextureSampler::Initialize())
{
NazaraError("Failed to initialize texture sampler");
Uninitialize();
return false;
}
// Loaders
NzLoaders_Texture_Register();

View File

@ -26,6 +26,8 @@ bool NzUtility::Initialize()
if (!NzCore::Initialize())
{
NazaraError("Failed to initialize core module");
Uninitialize();
return false;
}
@ -33,19 +35,23 @@ bool NzUtility::Initialize()
if (!NzBuffer::Initialize())
{
NazaraError("Failed to initialize buffers");
Uninitialize();
return false;
}
if (!NzPixelFormat::Initialize())
{
NazaraError("Failed to initialize pixel formats");
Uninitialize();
return false;
}
if (!NzWindow::Initialize())
{
NazaraError("Failed to initialize window's system");
NzPixelFormat::Uninitialize();
Uninitialize();
return false;
}