Skip to content

Commit e349dfe

Browse files
fix: fix panic caused by removed_resource.is_none (fix #11955) (#12000)
1 parent fdaf48f commit e349dfe

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changes/fix-resource-id.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': patch:bug
3+
---
4+
5+
Fixed a panic caused by an assert when the resource random id has been used already.

crates/tauri/src/resources/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ impl ResourceTable {
111111
///
112112
/// Returns a unique resource ID, which acts as a key for this resource.
113113
pub fn add_arc_dyn(&mut self, resource: Arc<dyn Resource>) -> ResourceId {
114-
let rid = Self::new_random_rid();
114+
let mut rid = Self::new_random_rid();
115+
while self.index.contains_key(&rid) {
116+
rid = Self::new_random_rid();
117+
}
118+
115119
let removed_resource = self.index.insert(rid, resource);
116120
assert!(removed_resource.is_none());
117121
rid

0 commit comments

Comments
 (0)