diff --git a/.changes/fix-resource-id.md b/.changes/fix-resource-id.md new file mode 100644 index 000000000..177f8a7bf --- /dev/null +++ b/.changes/fix-resource-id.md @@ -0,0 +1,5 @@ +--- +'tauri': patch:bug +--- + +Fixed a panic caused by an assert when the resource random id has been used already. \ No newline at end of file diff --git a/crates/tauri/src/resources/mod.rs b/crates/tauri/src/resources/mod.rs index 2c7fa0182..72498503c 100644 --- a/crates/tauri/src/resources/mod.rs +++ b/crates/tauri/src/resources/mod.rs @@ -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) -> 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