dethrace-labs / dethrace

Reverse engineering the 1997 game "Carmageddon"
https://twitter.com/dethrace_labs
GNU General Public License v3.0
669 stars 38 forks source link

Audio is not cleaned up on shutdown #328

Open madebr opened 1 year ago

madebr commented 1 year ago

In S3Shutdown, the descriptors are cleaned up with the following code: https://github.com/dethrace-labs/dethrace/blob/07d517307a2be88e086f8b94d53327072b8cf50d/src/S3/audio.c#L103-L113

However, S3Disable disables gS3_enabled: https://github.com/dethrace-labs/dethrace/blob/07d517307a2be88e086f8b94d53327072b8cf50d/src/S3/audio.c#L124-L126

Which causes S3DisposeDescriptor to never do anything: https://github.com/dethrace-labs/dethrace/blob/07d517307a2be88e086f8b94d53327072b8cf50d/src/S3/audio.c#L193-L200

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();