diff --git a/filament/backend/src/metal/MetalDriver.mm b/filament/backend/src/metal/MetalDriver.mm index 8e49c90dd7d4..10b242ec7d1e 100644 --- a/filament/backend/src/metal/MetalDriver.mm +++ b/filament/backend/src/metal/MetalDriver.mm @@ -872,6 +872,15 @@ void MetalDriver::destroyDescriptorSet(Handle dsh) { DEBUG_LOG("destroyDescriptorSet(dsh = %d)\n", dsh.getId()); + + // 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; + } + } + if (dsh) { executeAfterCurrentCommandBufferCompletes( [this, dsh]() mutable { destruct_handle(dsh); });