Skip to content

Subsystems may be shut down while they're still being used #1248

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

Open
daggerbot opened this issue Aug 20, 2022 · 1 comment
Open

Subsystems may be shut down while they're still being used #1248

daggerbot opened this issue Aug 20, 2022 · 1 comment

Comments

@daggerbot
Copy link
Contributor

If two different instances of a subsystem object are acquired from the main Sdl object, the subsystem will be shut down when any one of these instances is dropped. For example:

extern crate sdl2;

fn main() {
    let sdl = sdl2::init().unwrap();
    let _video1 = sdl.video().unwrap();
    {
        let _video2 = sdl.video().unwrap();
    } // SDL_QuitSubSystem is called here
    // ...
}

SDL_QuitSubSystem is called when _video2 is dropped even though _video1 is still alive. This is because each instance holds a reference to a different SubsystemDrop.

A possible solution is to store a Weak<SubsystemDrop> for each subsystem in the main SdlDrop. Then when the subsystem is requested, the SubsystemDrop can be acquired from here if it already exists.

@daggerbot daggerbot changed the title Subsystems may be dropped while they're still being used Subsystems may be shut down while they're still being used Aug 20, 2022
@Cobrand
Copy link
Member

Cobrand commented Aug 23, 2022

Like in my reply there: #1247 (comment)

We could use atomic integers to prevent a subsystem being destroyed when it shouldn't. And while we're at it, we could prevent a subsystem from being initialized if it has already been initialized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants