Skip to content

Conversation

@MarijnS95
Copy link
Member

@MarijnS95 MarijnS95 commented Nov 23, 2025

Fixes #3206

Surface creation and destruction events exist "specifically" for Android which has diverging lifetimes for its Surface structure compared to other platforms; specifically Vulkan VkSurfaceKHR or EGLSurface objects need to be destroyed and recreated.

Commit 6cdb317 ("Consistently deliver a Resumed event on all platforms") made sure to consistently call can_create_surfaces() (Event::Resumed back then) on all platforms directly after startup so that users don't have to have platform-specific surface creation behaviour in two disjoint places, but we forgot about destroy_surfaces() (back then Event::Suspended) leading to applications still having to handle this destruction in two different places.

Solve that by calling the callback on all those platforms, directly before returning PumpStatus::Exit from fn single_iteration() or fn pump_app_events() (on Appkit).

Tested on:

  • Android this was already supported before this PR, of course; but would be useful to check/assert that Android (the two backends android-activity hosts currently) consistently emit this event before exiting the loop however.
  • Wayland
  • X11
  • Appkit
  • UIkit: code missing, should be in CFRunLoopActivity::Exit?
  • Win32
  • Web (TODO: Not yet added)
  • Orbital

Important

Draft because this is entirely untested and may not even compile on all platforms. The samples likely still need to be updated to match the new behaviour too.

In a distant future (before Winit 0.31 perhaps) these events should perhaps be moved to WindowEvent, as outlined in #4420.

@MarijnS95 MarijnS95 changed the title Emit destroy_surfaces() event consistently on all platforms Emit destroy_surfaces() consistently on all platforms Nov 23, 2025
@MarijnS95 MarijnS95 force-pushed the consistent-destroy-surfaces branch 2 times, most recently from 4948b84 to b9475de Compare January 21, 2026 21:52
Surface creation and destruction events exist "specifically" for Android
which has diverging lifetimes for its `Surface` structure compared to
other platforms; specifically Vulkan `VkSurfaceKHR` or `EGLSurface`
objects need to be destroyed and recreated.

Commit 6cdb317 ("Consistently deliver a Resumed event on all
platforms") made sure to consistently call `can_create_surfaces()`
(`Event::Resumed` back then) on all platforms directly after
startup so that users don't have to have platform-specific surface
creation behaviour in two disjoint places, but we forgot about
`destroy_surfaces()` (back then `Event::Suspended`) leading to
applications still having to handle this destruction in two different
places.

Solve that by calling the callback on all those platforms, directly
before returning `PumpStatus::Exit` from `fn single_iteration()`.
@MarijnS95 MarijnS95 force-pushed the consistent-destroy-surfaces branch from b9475de to 1e4c538 Compare January 21, 2026 22:14
Comment on lines -290 to +292
/// Dispatch control flow events (`NewEvents`, `AboutToWait`, and
/// `LoopExiting`) as necessary to bring the internal `RunnerState` to the
/// new runner state.
/// Dispatch control flow events ([`ApplicationHandler::new_events()`] and
/// [`ApplicationHandler::about_to_wait()`]) as necessary to bring the internal [`RunnerState`]
/// to the new runner state.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw while looking through places to modify code, I found lots of these cases where no intradoc-links are used, in turn allowing completely stale references to inexistent identifiers to exist in the codebase (LoopExiting is gone in favour of dropping App, or is it not?).

A simple cargo doc test with disallowed warnings would have found them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Emit destroy_surfaces() on every platform before LoopDestroyed for surface-cleanup feature parity?

1 participant