-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toast example crahses if two or more toasts are removed at the same time #2336
Labels
bug
Something isn't working
Comments
Maybe a solution to this crash, it seemes to fix the panics. fn on_event( .. ) -> .. {
if let Event::Window(_, window::Event::RedrawRequested(now)) = &event
{
let mut next_redraw: Option<window::RedrawRequest> = None;
let mut removed_index = 0; // Add this to keep track of the removed index
self.instants.iter_mut().enumerate().for_each(
|(index, maybe_instant)| {
if let Some(instant) = maybe_instant.as_mut() {
let remaining =
Duration::from_secs(self.timeout_secs)
.saturating_sub(instant.elapsed());
if remaining == Duration::ZERO {
maybe_instant.take();
shell.publish((self.on_close)(index - removed_index)); // Adjust the toast to be removed, so the program wouldn't panic
removed_index += 1; // Increment beacuse one toast was removed
next_redraw =
Some(window::RedrawRequest::NextFrame);
} else {
let redraw_at =
window::RedrawRequest::At(*now + remaining);
next_redraw = next_redraw
.map(|redraw| redraw.min(redraw_at))
.or(Some(redraw_at));
}
}
},
);
..
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an existing issue for this?
Is this issue related to iced?
What happened?
If you add another toast in the new method and then run the example and wait 5 seconds it will crash, because the program tries to remove a toast at position 1, but there is only 1 toast left in the Vec, so the program panics.
How the
new
method should look to reproduce:What is the expected behavior?
That the program didn't panic and just removed both toast without a problem.
Version
master
Operating System
Windows
Do you have any log output?
The text was updated successfully, but these errors were encountered: