diff --git a/Source/CesiumRuntime/Private/CesiumTextureUtility.cpp b/Source/CesiumRuntime/Private/CesiumTextureUtility.cpp index a8f2f8c3b..f1a13b663 100644 --- a/Source/CesiumRuntime/Private/CesiumTextureUtility.cpp +++ b/Source/CesiumRuntime/Private/CesiumTextureUtility.cpp @@ -762,7 +762,8 @@ TextureAddress convertGltfWrapTToUnreal(int32_t wrapT) { } } -CesiumAsync::SharedFuture createMipMapsForSampler( +std::optional> +createMipMapsForSampler( const CesiumAsync::AsyncSystem& asyncSystem, const CesiumGltf::Sampler& sampler, CesiumGltf::ImageCesium& image) { @@ -776,13 +777,6 @@ CesiumAsync::SharedFuture createMipMapsForSampler( return extension.preprocessFuture.value(); } - CesiumAsync::Promise promise = - asyncSystem.createPromise(); - - extension.preprocessFuture = promise.getFuture().share(); - - lock.unlock(); - // Generate mipmaps if needed. // An image needs mipmaps generated for it if: // 1. It is used by a Texture that has a Sampler with a mipmap filtering @@ -806,10 +800,19 @@ CesiumAsync::SharedFuture createMipMapsForSampler( } if (!needsMipmaps || image.pixelData.empty()) { - promise.resolve(&image); - return *extension.preprocessFuture; + // If we don't need mipmaps, we don't want to create a future for them. + // This allows a future sampler using this image that does need mipmaps to + // generate them. + return std::nullopt; } + CesiumAsync::Promise promise = + asyncSystem.createPromise(); + + extension.preprocessFuture = promise.getFuture().share(); + + lock.unlock(); + // We need mipmaps generated. std::optional errorMessage = CesiumGltfReader::GltfReader::generateMipMaps(image); @@ -829,10 +832,16 @@ CesiumAsync::SharedFuture createMipMapsForAllTextures( CesiumGltf::Model& model) { std::vector> futures; for (const Texture& texture : model.textures) { - futures.push_back(createMipMapsForSampler( - asyncSystem, - model.getSafe(model.samplers, texture.sampler), - *model.images[texture.source].cesium)); + const CesiumGltf::Sampler& sampler = + model.getSafe(model.samplers, texture.sampler); + std::optional> + optionalFuture = createMipMapsForSampler( + asyncSystem, + sampler, + *model.images[texture.source].cesium); + if (optionalFuture.has_value()) { + futures.push_back(optionalFuture.value()); + } } return asyncSystem.all(std::move(futures))