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

Audio is not cleaned up on shutdown #328

Open
madebr opened this issue May 6, 2023 · 0 comments
Open

Audio is not cleaned up on shutdown #328

madebr opened this issue May 6, 2023 · 0 comments

Comments

@madebr
Copy link
Collaborator

madebr commented May 6, 2023

In S3Shutdown, the descriptors are cleaned up with the following code:

dethrace/src/S3/audio.c

Lines 103 to 113 in 07d5173

S3Disable();
for (descriptor = gS3_descriptors; descriptor != NULL; descriptor = next_descriptor) {
next_descriptor = descriptor->next;
S3DisposeDescriptor(descriptor->id);
S3MemFree(descriptor);
}
for (outlet = gS3_outlets; outlet != NULL; outlet = next_outlet) {
next_outlet = outlet->next;
S3DisposeOutlet(outlet);
}
S3DisposeUnboundChannels();

However, S3Disable disables gS3_enabled:

dethrace/src/S3/audio.c

Lines 124 to 126 in 07d5173

void S3Disable(void) {
S3StopAllOutletSounds();
gS3_enabled = 0;

Which causes S3DisposeDescriptor to never do anything:

dethrace/src/S3/audio.c

Lines 193 to 200 in 07d5173

int S3DisposeDescriptor(tS3_sound_id id) {
tS3_channel* c; // [esp+Ch] [ebp-10h]
tS3_outlet* o; // [esp+10h] [ebp-Ch]
tS3_descriptor* desc; // [esp+14h] [ebp-8h]
if (!gS3_enabled) {
return 0;
}

Applying the following patch to disable S3 after disposal of all descriptors causes infinite recursion:
(the patch is also incorrect, becuase S3Disable stops all outlet sounds before descriptors are destroyed)

--- a/src/S3/audio.c
+++ b/src/S3/audio.c
@@ -100,7 +100,9 @@ void S3Shutdown(void) {
     S3DisableMIDI();
     S3DisableCDA();
     if (gS3_enabled) {
+#if !defined(DETHRACE_FIX_BUGS)
         S3Disable();
+#endif
         for (descriptor = gS3_descriptors; descriptor != NULL; descriptor = next_descriptor) {
             next_descriptor = descriptor->next;
             S3DisposeDescriptor(descriptor->id);
@@ -111,6 +113,9 @@ void S3Shutdown(void) {
             S3DisposeOutlet(outlet);
         }
         S3DisposeUnboundChannels();
+#if defined(DETHRACE_FIX_BUGS)
+        S3Disable();
+#endif
     }
     if (gS3_opened_output_devices) {
         S3CloseDevices();
@madebr madebr changed the title Audio is not cleaned-up on shutdown Audio is not cleaned up on shutdown May 6, 2023
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

1 participant