From d7d351fc636830135d92d17d80c550b7798c2a8d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 12:50:52 -0800 Subject: [PATCH] Guard against unloaded env cubemaps --- .../src/EntityTreeRenderer.cpp | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index dc59d40e82..28a89162ba 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -140,8 +140,8 @@ void EntityTreeRenderer::update() { // If we haven't already updated and previously attempted to load a texture, // check if the texture loaded and apply it if (!updated && ( - (_pendingSkyboxTexture && _skyboxTexture && _skyboxTexture->isLoaded()) || - (_pendingAmbientTexture && _ambientTexture && _ambientTexture->isLoaded()))) { + (_pendingSkyboxTexture && (!_skyboxTexture || _skyboxTexture->isLoaded())) || + (_pendingAmbientTexture && (!_ambientTexture && _ambientTexture->isLoaded())))) { applyZonePropertiesToScene(_bestZone); } @@ -326,15 +326,19 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetTexture(zone->getKeyLightProperties().getAmbientURL(), CUBE_TEXTURE); - if (_ambientTexture && _ambientTexture->isLoaded() && _ambientTexture->getGPUTexture()) { + _pendingAmbientTexture = true; + + if (_ambientTexture && _ambientTexture->isLoaded()) { _pendingAmbientTexture = false; - if (_ambientTexture->getGPUTexture()->getIrradiance()) { - sceneKeyLight->setAmbientSphere(_ambientTexture->getGPUTexture()->getIrradiance()); - sceneKeyLight->setAmbientMap(_ambientTexture->getGPUTexture()); + + auto texture = _ambientTexture->getGPUTexture(); + if (texture) { + sceneKeyLight->setAmbientSphere(texture->getIrradiance()); + sceneKeyLight->setAmbientMap(texture); isAmbientTextureSet = true; + } else { + qCDebug(entitiesrenderer) << "Failed to load ambient texture:" << zone->getKeyLightProperties().getAmbientURL(); } - } else { - _pendingAmbientTexture = true; } } @@ -353,24 +357,27 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetSkyboxProperties().getURL().isEmpty()) { - skybox->setCubemap(gpu::TexturePointer()); + skybox->setCubemap(nullptr); _pendingSkyboxTexture = false; _skyboxTexture.clear(); } else { // Update the Texture of the Skybox with the one pointed by this zone _skyboxTexture = textureCache->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE); + _pendingSkyboxTexture = true; + + if (_skyboxTexture && _skyboxTexture->isLoaded()) { + _pendingSkyboxTexture = false; - if (_skyboxTexture && _skyboxTexture->isLoaded() && _skyboxTexture->getGPUTexture()) { auto texture = _skyboxTexture->getGPUTexture(); skybox->setCubemap(texture); - _pendingSkyboxTexture = false; - if (!isAmbientTextureSet && texture->getIrradiance()) { + if (!isAmbientTextureSet) { sceneKeyLight->setAmbientSphere(texture->getIrradiance()); sceneKeyLight->setAmbientMap(texture); isAmbientTextureSet = true; } } else { - _pendingSkyboxTexture = true; + skybox->setCubemap(nullptr); + qCDebug(entitiesrenderer) << "Failed to load skybox:" << zone->getSkyboxProperties().getURL(); } }