fix: fix panic caused by removed_resource.is_none (fix #11955) (#12000)

This commit is contained in:
stringhandler
2024-12-23 16:11:31 +02:00
committed by GitHub
parent fdaf48fc4a
commit e349dfe572
2 changed files with 10 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'tauri': patch:bug
---
Fixed a panic caused by an assert when the resource random id has been used already.

View File

@@ -111,7 +111,11 @@ impl ResourceTable {
///
/// Returns a unique resource ID, which acts as a key for this resource.
pub fn add_arc_dyn(&mut self, resource: Arc<dyn Resource>) -> ResourceId {
let rid = Self::new_random_rid();
let mut rid = Self::new_random_rid();
while self.index.contains_key(&rid) {
rid = Self::new_random_rid();
}
let removed_resource = self.index.insert(rid, resource);
assert!(removed_resource.is_none());
rid