rakslice / macemu

Basilisk II and SheepShaver Macintosh emulators
0 stars 0 forks source link

fatal error on second audio playback #38

Closed rakslice closed 3 years ago

rakslice commented 3 years ago

The first playback of audio in an application after startup works fine, but when I exit and launch the application again, audio playback causes various kinds of fatal error.

I can stop and start and close and reopen the same or different files in the application an unlimited number of times, it's just the playback after the first application launched that played audio has exited that has the problem.

SS: The error takes a variety of forms at random:

BII:

Investigating SS unhandled segfault further in gdb, I find that it's in various delegated calls in audio.cpp, not always the same one, but in or soon after the InitOutputDevice of the second audio session.

With DEBUG set in audio.cpp:

Start and first audio session:

warning: B2: 10/20/20 15:07:32:229 SoundInOpen
warning: B2: 10/20/20 15:07:32:234 SoundInStatus 2
[New Thread 10724.0x6464]
warning: B2: 10/20/20 15:08:09:191 AudioDispatch params 0bff583e (size 4), what -1
warning: B2: 10/20/20 15:08:09:198  global data at 000ff770
warning: B2: 10/20/20 15:08:09:205 AudioDispatch params 0bff5890 (size 0), what -5
warning: B2: 10/20/20 15:08:09:210 AudioDispatch params 0bff585e (size 4), what -2
warning: B2: 10/20/20 15:08:16:761 AudioDispatch params 0f6abc46 (size 4), what -1
warning: B2: 10/20/20 15:08:16:768  global data at 00c77f70
warning: B2: 10/20/20 15:08:16:772 AudioDispatch params 0f6abcc8 (size 12), what 259
warning: B2: 10/20/20 15:08:16:780  AudioGetInfo hvol, infoPtr 0f6abe18, source ID 00000
000
warning: B2: 10/20/20 15:08:16:786 AudioDispatch params 0f6abc88 (size 4), what -2
warning: B2: 10/20/20 15:08:30:074 AudioDispatch params 0dbef4e6 (size 4), what -1
warning: B2: 10/20/20 15:08:30:081  global data at 0d820c10
warning: B2: 10/20/20 15:08:30:085 AudioDispatch params 0dbef534 (size 4), what 1
warning: B2: 10/20/20 15:08:30:093  InitOutputDevice
warning: B2: 10/20/20 15:08:30:119  OpenMixer() returns 00000000, mixer 00920003
warning: B2: 10/20/20 15:08:30:128 AudioDispatch params 0dbef570 (size 4), what 257
warning: B2: 10/20/20 15:08:30:135  AddSource
warning: B2: 10/20/20 15:08:30:142  delegating call to Apple Mixer
warning: B2: 10/20/20 15:08:30:170  returns 00000000
warning: B2: 10/20/20 15:08:30:377 AudioDispatch params 0dbef08e (size 12), what 260
warning: B2: 10/20/20 15:08:30:384  AudioSetInfo volu, infoPtr 001f001f, source ID 00e29
810
warning: B2: 10/20/20 15:08:30:392   delegated to Apple Mixer, returns 00000000
warning: B2: 10/20/20 15:08:30:541 AudioDispatch params 0d7ff364 (size 6), what 262
warning: B2: 10/20/20 15:08:30:549  StopSource
warning: B2: 10/20/20 15:08:30:553  delegating call to Apple Mixer
warning: B2: 10/20/20 15:08:30:560  returns 00000000
warning: B2: 10/20/20 15:08:30:565 AudioDispatch params 0d7ff310 (size 12), what 259
warning: B2: 10/20/20 15:08:30:572  AudioGetInfo cmfa, infoPtr 00da6a2c, source ID 00e29
810
warning: B2: 10/20/20 15:08:30:581   delegated to Apple Mixer, returns ffffff19
warning: B2: 10/20/20 15:08:30:593 AudioDispatch params 0d7ff362 (size 12), what 264
warning: B2: 10/20/20 15:08:30:600  PlaySourceBuffer flags 00000001
warning: B2: 10/20/20 15:08:30:611  returns 00000000
warning: B2: 10/20/20 15:08:30:619 AudioDispatch params 0d7ff2f6 (size 12), what 259
warning: B2: 10/20/20 15:08:30:628  AudioGetInfo cmfa, infoPtr 00da6a2c, source ID 00e29
810

...

warning: B2: 10/20/20 15:08:33:625 AudioDispatch params 0f71dd5c (size 12), what 259
warning: B2: 10/20/20 15:08:33:632  AudioGetInfo cmfa, infoPtr 00da6a2c, source ID 00e29
810
warning: B2: 10/20/20 15:08:33:639   delegated to Apple Mixer, returns ffffff19
warning: B2: 10/20/20 15:08:33:683 AudioDispatch params 0dbf3994 (size 6), what 262
warning: B2: 10/20/20 15:08:33:692  StopSource
warning: B2: 10/20/20 15:08:33:695  delegating call to Apple Mixer
warning: B2: 10/20/20 15:08:33:702  returns 00000000
warning: B2: 10/20/20 15:08:33:710 AudioDispatch params 0dbf39a6 (size 6), what 262
warning: B2: 10/20/20 15:08:33:717  StopSource
warning: B2: 10/20/20 15:08:33:720  delegating call to Apple Mixer
warning: B2: 10/20/20 15:08:33:727  returns 00000000
warning: B2: 10/20/20 15:08:33:731 AudioDispatch params 0dbf3a04 (size 4), what 258
warning: B2: 10/20/20 15:08:33:737  RemoveSource
warning: B2: 10/20/20 15:08:33:743  delegating call to Apple Mixer
warning: B2: 10/20/20 15:08:33:750  returns 00000000
warning: B2: 10/20/20 15:08:33:756 AudioDispatch params 0dbf39b8 (size 4), what -2

Then, starting the second session (note the invalid zero mixer value from OpenMixer(), though the crash is sometimes before that so it may be a knock-on effect:

warning: B2: 10/20/20 15:11:11:461 AudioDispatch params 0dbff4e6 (size 4), what -1
warning: B2: 10/20/20 15:11:11:468 AudioDispatch params 0dbff534 (size 4), what 1
warning: B2: 10/20/20 15:11:11:475  InitOutputDevice
warning: B2: 10/20/20 15:11:11:479  OpenMixer() returns 00000000, mixer 00000000
warning: B2: 10/20/20 15:11:11:486 AudioDispatch params 0dbff570 (size 4), what 257
warning: B2: 10/20/20 15:11:11:494  AddSource
warning: B2: 10/20/20 15:11:11:497  delegating call to Apple Mixer
warning: B2: 10/20/20 15:11:11:501  returns 00000000
warning: B2: 10/20/20 15:11:11:634 AudioDispatch params 0dbff08e (size 12), what 260
warning: B2: 10/20/20 15:11:11:641  AudioSetInfo volu, infoPtr 001f001f, source ID 00000
000
warning: B2: 10/20/20 15:11:11:775 AudioDispatch params 0d80f374 (size 6), what 262
warning: B2: 10/20/20 15:11:11:782  StopSource
warning: B2: 10/20/20 15:11:11:785  delegating call to Apple Mixer

Thread 1 hit Catchpoint 2 (signal SIGSEGV), 0x0000000007642a4b in ?? ()
1: x/i $pc
=> 0x7642a4b:   movzwl 0x11000000(%r12d,%eax,1),%ebx
2: /x $rsp = 0x115f318
x86 pc 7642a4b mac pc 40c9db18
Pattern not found.
(gdb) p /x $r12d+$eax+1
$1 = 0xffffffff
rakslice commented 3 years ago

While testing in BII in Mac OS 7.6.1 with repeated launches of the stock MoviePlayer 2.5 with a WAV file it can conveniently play back, I found a particular kind of pattern:

This is consistent with sound being left in a good or bad state based on the previous app that played sound (or the initial state when no app has played audio yet), but with a one application run delay in the effect showing up -- i.e. not affecting not the next application run that plays audio, only the one after that.

rakslice commented 3 years ago

This is not a new error; in older posted BII Windows builds the error was a "Type 10 Error" rather than "unimplemented trap"

rakslice commented 3 years ago

Also happens on Linux, though with different errors, e.g. BII just segfaults

rakslice commented 3 years ago

A cursory look at the forums finds a lot of stuff that could be down to this.

In the thread at https://www.emaculation.com/forum/viewtopic.php?t=5286 someone suggests turning on 'platinum' sound effects in Mac OS 9; this generates a lot of little random sound effects on Finder UI actions, which have the side effect of keeping the system away from whatever precondition is the problem

rakslice commented 3 years ago

Due to an errant early return, the deinitialization does not complete properly in the case where there was a mixer to close

rakslice commented 3 years ago

This is a bug from prehistory https://github.com/rakslice/macemu/blame/3e58028cb14cdcbd2d2798055c1e863ed663e693/BasiliskII/src/audio.cpp#L405

rakslice commented 3 years ago

I gave Cockatrice III a heads up because this goes back to BII 0.8 code, but testing their build it doesn't seem to have any effect like this playback crash there.

https://sourceforge.net/p/cockatrice/tickets/2/