diff --git a/filament/backend/src/metal/MetalDriver.mm b/filament/backend/src/metal/MetalDriver.mm index 8e49c90dd7d..bee3ba88355 100644 --- a/filament/backend/src/metal/MetalDriver.mm +++ b/filament/backend/src/metal/MetalDriver.mm @@ -872,10 +872,20 @@ void MetalDriver::destroyDescriptorSet(Handle dsh) { DEBUG_LOG("destroyDescriptorSet(dsh = %d)\n", dsh.getId()); - if (dsh) { - executeAfterCurrentCommandBufferCompletes( - [this, dsh]() mutable { destruct_handle(dsh); }); + if (!dsh) { + return; + } + + // Unbind this descriptor set. + auto* descriptorSet = handle_cast(dsh); + for (size_t i = 0; i < MAX_DESCRIPTOR_SET_COUNT; i++) { + if (UTILS_UNLIKELY(mContext->currentDescriptorSets[i] == descriptorSet)) { + mContext->currentDescriptorSets[i] = nullptr; + } } + + executeAfterCurrentCommandBufferCompletes( + [this, dsh]() mutable { destruct_handle(dsh); }); } void MetalDriver::terminate() {