Repository navigation
Preserve MSCDEX entries when remounting CD drives #2605
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1354,9 +1354,9 @@ private void MountCdRomImages(char driveLetter, IReadOnlyList<string> imagePaths | |
| CdRomDrive drive = new CdRomDrive(images, _channelCreator, _activityNotifier, driveLetter); | ||
| byte driveIndex = DosDriveManager.TryGetLetterIndex(driveLetter, out int idx) ? (byte)idx : (byte)3; | ||
| MscdexDriveEntry entry = new MscdexDriveEntry(driveLetter, driveIndex, drive); | ||
| _mscdex.AddDrive(entry); | ||
| string volumeLabel = drive.Image.PrimaryVolume.VolumeIdentifier ?? string.Empty; | ||
| _driveManager.RegisterCdRomDriveLetter(driveLetter, string.Empty, volumeLabel, drive); | ||
| _mscdex.AddDrive(entry); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remounting a CD drive during CD audio playback can leave its audio callback reading a disposed image. The drive-letter replacement now removes the old MSCDEX entry before it adds the new one. Before this change, the removal disposed the newly mounted image, not the playing one. This change moves the disposal to the old image, so the playing callback now reads a disposed resource. Stop the old drive's playback, and stop its mixer callback from reading, before
|
||
| string paths = string.Join(", ", imagePaths); | ||
| WriteToStandardOutput($"Drive {driveLetter}: mounted {imagePaths.Count} CD-ROM image(s): {paths}\r\n"); | ||
| } catch (IOException ex) { | ||
|
|
@@ -1374,8 +1374,8 @@ private bool MountCdRomFolder(char driveLetter, string hostPath) { | |
| CdRomDrive drive = new CdRomDrive(image, _channelCreator, _activityNotifier, driveLetter); | ||
| byte driveIndex = DosDriveManager.TryGetLetterIndex(driveLetter, out int idx) ? (byte)idx : (byte)3; | ||
| MscdexDriveEntry entry = new MscdexDriveEntry(driveLetter, driveIndex, drive); | ||
| _mscdex.AddDrive(entry); | ||
| _driveManager.RegisterCdRomDriveLetter(driveLetter, hostPath, volumeLabel, drive); | ||
| _mscdex.AddDrive(entry); | ||
| return true; | ||
| } catch (IOException ex) { | ||
| WriteToStandardOutput($"MOUNT: failed to create CD-ROM drive from folder: {ex.Message}\r\n"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ; Build: fasm mscdex_drive_count.asm mscdex_drive_count.com | ||
| ; Queries the MSCDEX CD drive count with INT 2Fh AH=15h AL=00h, writes the count | ||
| ; (BX) as one byte to standard output with INT 21h AH=40h, then exits. The test | ||
| ; reads the output byte back and expects the CD drive to still be registered. | ||
| use16 | ||
| org 100h | ||
|
|
||
| mov ah, 15h | ||
| mov al, 0 | ||
| int 2Fh | ||
| mov [count], bl | ||
| mov ah, 40h | ||
| mov bx, 1 | ||
| mov cx, 1 | ||
| mov dx, count | ||
| int 21h | ||
| mov ax, 4C00h | ||
| int 21h | ||
|
|
||
| count: rb 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait for an active callback before disposing the image.
If the audio callback has already passed its playing-status check,
StopPlaybackdisables the channel but does not wait for that callback. The callback can then read the image after Line 168 disposes it. A direct drive unmount can reach this sequence while audio plays. Quiesce the callback before disposal. (raw.githubusercontent.com)Unmounting a playing CD can hang the mixer thread.
StopAudiodisables the CD channel whileSoundChannel.Mixcan still run. IfMixpasses itsIsEnabledcheck before the disable, and then assigns_framesNeededafterEnable(false)clears it, the loop never exits. The CD callback returns without adding frames once playback is stopped, soAudioFrames.Countstays at 0. Disabling an already disabled channel returns early and does not clear_framesNeeded.Mixthen calls the handler indefinitely, and the mixer thread does not return to write output.This PR adds a new trigger.
RemoveDrivenow callsStopAudio()(Mscdex.cs:167) while the mixer thread runs concurrently. The same window already exists for the otherStopAudiocallers inMscdex.cs.Make the enabled check and the
_framesNeededassignment one step under_mutex. Re-checkIsEnabledunder_mutexbefore each handler call, and exit the loop when the channel is disabled. Then a disable that completes after the check clears_framesNeeded, and a disable that completes before the check causes an early return.