Fixed the crash that happened when destroying then creating again a render target
This commit is contained in:
parent
df6874273a
commit
fd0d18f12e
@ -31,7 +31,7 @@
|
|||||||
#include <SFML/System/Lock.hpp>
|
#include <SFML/System/Lock.hpp>
|
||||||
#include <SFML/OpenGL.hpp>
|
#include <SFML/OpenGL.hpp>
|
||||||
#include <SFML/Window/glext/glext.h>
|
#include <SFML/Window/glext/glext.h>
|
||||||
#include <vector>
|
#include <set>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
@ -67,17 +67,29 @@ namespace
|
|||||||
|
|
||||||
// Internal contexts
|
// Internal contexts
|
||||||
sf::ThreadLocalPtr<sf::priv::GlContext> internalContext(NULL);
|
sf::ThreadLocalPtr<sf::priv::GlContext> internalContext(NULL);
|
||||||
std::vector<sf::priv::GlContext*> internalContexts;
|
std::set<sf::priv::GlContext*> internalContexts;
|
||||||
sf::Mutex internalContextsMutex;
|
sf::Mutex internalContextsMutex;
|
||||||
|
|
||||||
|
// Check if the internal context of the current thread is valid
|
||||||
|
bool HasInternalContext()
|
||||||
|
{
|
||||||
|
// The internal context can be null...
|
||||||
|
if (!internalContext)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// ... or non-null but deleted from the list of internal contexts
|
||||||
|
sf::Lock lock(internalContextsMutex);
|
||||||
|
return internalContexts.find(internalContext) != internalContexts.end();
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve the internal context for the current thread
|
// Retrieve the internal context for the current thread
|
||||||
sf::priv::GlContext* GetInternalContext()
|
sf::priv::GlContext* GetInternalContext()
|
||||||
{
|
{
|
||||||
if (!internalContext)
|
if (!HasInternalContext())
|
||||||
{
|
{
|
||||||
internalContext = sf::priv::GlContext::New();
|
internalContext = sf::priv::GlContext::New();
|
||||||
sf::Lock lock(internalContextsMutex);
|
sf::Lock lock(internalContextsMutex);
|
||||||
internalContexts.push_back(internalContext);
|
internalContexts.insert(internalContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
return internalContext;
|
return internalContext;
|
||||||
@ -111,7 +123,7 @@ void GlContext::Cleanup()
|
|||||||
|
|
||||||
// Destroy the internal contexts
|
// Destroy the internal contexts
|
||||||
sf::Lock lock(internalContextsMutex);
|
sf::Lock lock(internalContextsMutex);
|
||||||
for (std::vector<GlContext*>::iterator it = internalContexts.begin(); it != internalContexts.end(); ++it)
|
for (std::set<GlContext*>::iterator it = internalContexts.begin(); it != internalContexts.end(); ++it)
|
||||||
delete *it;
|
delete *it;
|
||||||
internalContexts.clear();
|
internalContexts.clear();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user