Made context creation exception-safe
Former-commit-id: d55687cea712a34e905b3f2f2d85611d1d0b1b74
This commit is contained in:
parent
81672a5ff6
commit
9ba6258478
|
|
@ -5,6 +5,7 @@
|
|||
// Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila
|
||||
|
||||
#include <Nazara/Renderer/Win32/ContextImpl.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/LockGuard.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
|
|
@ -42,11 +43,16 @@ bool NzContextImpl::Create(NzContextParameters& parameters)
|
|||
m_ownsWindow = true;
|
||||
}
|
||||
|
||||
// En cas d'exception, la ressource sera quand même libérée
|
||||
NzCallOnExit onExit([this] ()
|
||||
{
|
||||
Destroy();
|
||||
});
|
||||
|
||||
m_deviceContext = GetDC(m_window);
|
||||
if (!m_deviceContext)
|
||||
{
|
||||
NazaraError("Failed to get device context");
|
||||
Destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -116,8 +122,6 @@ bool NzContextImpl::Create(NzContextParameters& parameters)
|
|||
if (pixelFormat == 0)
|
||||
{
|
||||
NazaraError("Failed to choose pixel format");
|
||||
Destroy();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -125,7 +129,6 @@ bool NzContextImpl::Create(NzContextParameters& parameters)
|
|||
if (!SetPixelFormat(m_deviceContext, pixelFormat, &descriptor))
|
||||
{
|
||||
NazaraError("Failed to set pixel format");
|
||||
Destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -191,10 +194,11 @@ bool NzContextImpl::Create(NzContextParameters& parameters)
|
|||
if (!m_context)
|
||||
{
|
||||
NazaraError("Failed to create context");
|
||||
Destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue