From 34bcbfaec95f980bef7633855ac6ad91ca127f36 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 1 Apr 2013 19:21:07 -0400 Subject: [PATCH] don't attempt to restore managed resources in GraphicsDevice::OnNewContext() if it's the first run (e.g. when things are guaranteed to be loaded already) --- src/framework/graphics/graphicsdevice.cpp | 17 +++++++++++++---- src/framework/graphics/graphicsdevice.h | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) 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)