summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gpu/command_buffer/common/id_allocator.cc8
-rw-r--r--gpu/command_buffer/common/id_allocator_test.cc15
2 files changed, 19 insertions, 4 deletions
diff --git a/gpu/command_buffer/common/id_allocator.cc b/gpu/command_buffer/common/id_allocator.cc
index e859282..eb450f3 100644
--- a/gpu/command_buffer/common/id_allocator.cc
+++ b/gpu/command_buffer/common/id_allocator.cc
@@ -55,10 +55,10 @@ bool IdAllocator::MarkAsUsed(ResourceId id) {
}
void IdAllocator::FreeID(ResourceId id) {
- GPU_DCHECK(id);
- used_ids_.erase(id);
- std::pair<ResourceIdSet::iterator, bool> result = free_ids_.insert(id);
- GPU_DCHECK(result.second);
+ if (id) {
+ used_ids_.erase(id);
+ free_ids_.insert(id);
+ }
}
bool IdAllocator::InUse(ResourceId id) const {
diff --git a/gpu/command_buffer/common/id_allocator_test.cc b/gpu/command_buffer/common/id_allocator_test.cc
index 69be2f0..624f959 100644
--- a/gpu/command_buffer/common/id_allocator_test.cc
+++ b/gpu/command_buffer/common/id_allocator_test.cc
@@ -110,4 +110,19 @@ TEST_F(IdAllocatorTest, AllocateIdAtOrAboveWrapsAround) {
EXPECT_EQ(2u, id3);
}
+TEST_F(IdAllocatorTest, RedundantFreeIsIgnored) {
+ IdAllocator* allocator = id_allocator();
+ ResourceId id1 = allocator->AllocateID();
+ allocator->FreeID(0);
+ allocator->FreeID(id1);
+ allocator->FreeID(id1);
+ allocator->FreeID(id1 + 1);
+
+ ResourceId id2 = allocator->AllocateID();
+ ResourceId id3 = allocator->AllocateID();
+ EXPECT_NE(id2, id3);
+ EXPECT_NE(kInvalidResource, id2);
+ EXPECT_NE(kInvalidResource, id3);
+}
+
} // namespace gpu