diff --git a/src/framework/graphics/graphicsdevice.cpp b/src/framework/graphics/graphicsdevice.cpp index 81bcd77..2783814 100644 --- a/src/framework/graphics/graphicsdevice.cpp +++ b/src/framework/graphics/graphicsdevice.cpp @@ -45,6 +45,8 @@ const unsigned int MAX_GPU_ATTRIB_SLOTS = 8; GraphicsDevice::GraphicsDevice(GameWindow *window) { STACK_TRACE; + m_hasNewContextRunYet = FALSE; + m_boundVertexBuffer = NULL; m_boundIndexBuffer = NULL; m_boundShader = NULL; @@ -147,10 +149,17 @@ void GraphicsDevice::OnNewContext() m_debugRenderer = new GeometryDebugRenderer(this); - m_solidColorTextures->OnNewContext(); - - for (ManagedResourceList::iterator i = m_managedResources.begin(); i != m_managedResources.end(); ++i) - (*i)->OnNewContext(); + // don't attempt to restore old graphics resources if this is the first + // new context event (meaning, any managed resources will be loaded at this point!) + if (m_hasNewContextRunYet) + { + m_solidColorTextures->OnNewContext(); + + for (ManagedResourceList::iterator i = m_managedResources.begin(); i != m_managedResources.end(); ++i) + (*i)->OnNewContext(); + } + + m_hasNewContextRunYet = TRUE; } void GraphicsDevice::OnLostContext() diff --git a/src/framework/graphics/graphicsdevice.h b/src/framework/graphics/graphicsdevice.h index 151ed3d..6661614 100644 --- a/src/framework/graphics/graphicsdevice.h +++ b/src/framework/graphics/graphicsdevice.h @@ -386,6 +386,8 @@ private: Sprite2DShader *m_sprite2dShader; Sprite3DShader *m_sprite3dShader; DebugShader *m_debugShader; + + BOOL m_hasNewContextRunYet; }; inline void GraphicsDevice::SetTextureParameters(const TextureParameters ¶ms)