Skip to content

Commit

Permalink
fix: fix panic caused by removed_resource.is_none (fix #11955) (#12000)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler authored Dec 23, 2024
1 parent fdaf48f commit e349dfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/fix-resource-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': patch:bug
---

Fixed a panic caused by an assert when the resource random id has been used already.
6 changes: 5 additions & 1 deletion crates/tauri/src/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e349dfe

Please sign in to comment.