@@ -25,13 +25,21 @@ class TestAllocator : public Allocator {
2525
2626 std::shared_ptr<DeviceBuffer> OnCreateBuffer (
2727 const DeviceBufferDescriptor& desc) override {
28+ if (should_fail) {
29+ return nullptr ;
30+ }
2831 return std::make_shared<MockDeviceBuffer>(desc);
2932 };
3033
3134 virtual std::shared_ptr<Texture> OnCreateTexture (
3235 const TextureDescriptor& desc) override {
36+ if (should_fail) {
37+ return nullptr ;
38+ }
3339 return std::make_shared<MockTexture>(desc);
3440 };
41+
42+ bool should_fail = false ;
3543};
3644
3745TEST (RenderTargetCacheTest, CachesUsedTexturesAcrossFrames) {
@@ -62,5 +70,20 @@ TEST(RenderTargetCacheTest, CachesUsedTexturesAcrossFrames) {
6270 ASSERT_EQ (render_target_cache.CachedTextureCount (), 1u );
6371}
6472
73+ TEST (RenderTargetCacheTest, DoesNotPersistFailedAllocations) {
74+ auto allocator = std::make_shared<TestAllocator>();
75+ auto render_target_cache = RenderTargetCache (allocator);
76+ auto desc = TextureDescriptor{
77+ .format = PixelFormat::kR8G8B8A8UNormInt ,
78+ .size = ISize (100 , 100 ),
79+ .usage = static_cast <TextureUsageMask>(TextureUsage::kRenderTarget )};
80+
81+ render_target_cache.Start ();
82+ allocator->should_fail = true ;
83+
84+ ASSERT_EQ (render_target_cache.CreateTexture (desc), nullptr );
85+ ASSERT_EQ (render_target_cache.CachedTextureCount (), 0u );
86+ }
87+
6588} // namespace testing
6689} // namespace impeller
0 commit comments