Skip to content
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

keep AudioSubsystem alive while AudioDevices or AudioStreama are alive #121

Merged
merged 3 commits into from
Feb 24, 2025

Conversation

antonilol
Copy link
Contributor

@antonilol antonilol commented Feb 19, 2025

breaking change because some functions allowed creating streams or devices without requiring an AudioSubsystem

fixes #79

Comment on lines +670 to 675
pub fn new(device_id: AudioDeviceID, audio_subsystem: AudioSubsystem) -> Self {
AudioDevice {
device_id,
audio_subsystem,
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be part of the public API?

@antonilol antonilol marked this pull request as draft February 19, 2025 13:02
@antonilol
Copy link
Contributor Author

antonilol commented Feb 19, 2025

I will later today check if this actually fixes the problem

Edit: it does

}

/// Create an `AudioStream` for this device with the specified spec.
/// This device will be closed when the stream is dropped.
/// The device begins paused, so you must call `stream.resume()` to start playback.
#[doc(alias = "SDL_OpenAudioDeviceStream")]
#[deprecated = "use `device.open_device_stream(spec)` (where device is an `AudioDevice`) instead"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What should happen with this function? It is almost identical to AudioDevice::open_device_stream (I added this in 57069b2 because it has 2 parameters that are fields of AudioDevice, so it is easier to call with only 1 parameter excluding self).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a successful SDL_OpenAudioDeviceStream call SDL will close the device when the stream is closed, so it makes sense to me to take an AudioDevice by value (self parameter there) in Rust.

@antonilol antonilol marked this pull request as ready for review February 21, 2025 08:41
@revmischa revmischa merged commit 7d530b1 into vhspace:master Feb 24, 2025
3 checks passed
@antonilol antonilol deleted the fix-audio-use-after-free branch February 24, 2025 18:45
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

Successfully merging this pull request may close these issues.

Memory corruption in SDL Audio
2 participants