mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-28 09:09:19 +01:00
fix(core): Free prepared ids that are never assigned (#10184)
This commit is contained in:
1 parent
73a7e97981
commit
2508e37a5e
2 files changed
+27
-1
No files matched your search
@@ -47,6 +47,7 @@ Bottom level categories:
|
||||
#### General
|
||||
|
||||
- Explicitly implement `Send` and `Sync` in `wgpu-core` to reduce the risk of `recursion_limit` overflow. By @nazar-pc in [#9953](https://github.com/gfx-rs/wgpu/pull/9953)
|
||||
- Fix a texture id leak when surface acquire returns no texture. By @jnb in [#10184](https://github.com/gfx-rs/wgpu/pull/10184).
|
||||
|
||||
## v30.0.1 (2026-08-21)
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ impl<T: StorageItem> Registry<T> {
|
||||
#[must_use]
|
||||
pub(crate) struct FutureId<'a, T: StorageItem> {
|
||||
id: Id<T::Marker>,
|
||||
identity: &'a IdentityManager<T::Marker>,
|
||||
data: &'a RwLock<Storage<T>>,
|
||||
}
|
||||
|
||||
@@ -73,7 +74,17 @@ impl<T: StorageItem> FutureId<'_, T> {
|
||||
pub fn assign(self, value: T) -> Id<T::Marker> {
|
||||
let mut data = self.data.write();
|
||||
data.insert(self.id, value);
|
||||
self.id
|
||||
// Assigned ids are freed by `Registry::remove`, not `Drop`.
|
||||
let id = self.id;
|
||||
core::mem::forget(self);
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
/// Free the id if it was never assigned, so that its index can be reused.
|
||||
impl<T: StorageItem> Drop for FutureId<'_, T> {
|
||||
fn drop(&mut self) {
|
||||
self.identity.free(self.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +98,7 @@ impl<T: StorageItem> Registry<T> {
|
||||
}
|
||||
None => self.identity.process(),
|
||||
},
|
||||
identity: &self.identity,
|
||||
data: &self.storage,
|
||||
}
|
||||
}
|
||||
@@ -169,4 +181,17 @@ mod tests {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dropped_ids_are_reused() {
|
||||
let registry = Registry::new();
|
||||
|
||||
let fid = registry.prepare(None);
|
||||
let index = fid.id.unzip().0;
|
||||
drop(fid);
|
||||
|
||||
let fid = registry.prepare(None);
|
||||
assert_eq!(fid.id.unzip().0, index);
|
||||
fid.assign(Arc::new(TestData));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user