fix: audio and other subsystems being dropped in App::new(), use Box::leak to ensure static ownership

This commit is contained in:
2025-08-12 13:07:17 -05:00
parent b91f70cf2f
commit c489f32908
4 changed files with 32 additions and 47 deletions

View File

@@ -138,20 +138,3 @@ impl SpriteAtlas {
self.default_color
}
}
/// Converts a `Texture` to a `Texture<'static>` using transmute.
///
/// # Safety
///
/// This function is unsafe because it uses `std::mem::transmute` to change the lifetime
/// of the texture from the original lifetime to `'static`. The caller must ensure that:
///
/// - The original `Texture` will live for the entire duration of the program
/// - No references to the original texture exist that could become invalid
/// - The texture is not dropped while still being used as a `'static` reference
///
/// This is typically used when you have a texture that you know will live for the entire
/// program duration and need to store it in a structure that requires a `'static` lifetime.
pub unsafe fn texture_to_static(texture: Texture) -> Texture<'static> {
std::mem::transmute(texture)
}