dirkwhoffmann / virtualc64

VirtualC64 is a cycle-accurate C64 emulator for macOS
https://dirkwhoffmann.github.io/virtualc64
Other
342 stars 33 forks source link

Bug: VirtualC64 4.6b1-Loading a directory or disk #752

Closed bluecursor closed 1 year ago

bluecursor commented 1 year ago

When double clicking a .d64 image into VirtualC64 4.6b1, performing a directory or load command causes a disk error as if a disk was not inserted. Right after when trying to insert a disk into a drop zone still causes the same error. Powering off/on or restarting the emulation still doest clear the error. Only by closing and reopening V64 then dropping in a drop zone does a disk image loads.

dirkwhoffmann commented 1 year ago

The disk did not get inserted. The bug came in when I started to utilize the new event scheduler for executing the disk change procedure. Up to now, I had this code in windowDidLoad:

      // Add media file (if provided on startup)
        mydocument.mm.addMedia()

        do {
            // Let the C64 throw an exception if it is not ready to power on
            try c64.isReady()

            // Start emulation
            try c64.run()

        } catch {

            // Open the Rom dialog
            openConfigurator(tab: "Roms")
        }

Function addMedia eventually calls insertDisk which is fine:

void
Drive::insertDisk(std::unique_ptr<Disk> disk)
{
    {   SUSPENDED

        if (!diskToInsert) {

            diskToInsert = std::move(disk);

            // Initiate the disk change procedure
            scheduleFirstDiskChangeEvent(DCH_INSERT);
        }
    }
}

The first DCH_INSERT is scheduled as expected. However, because try c64.run() is executed later, the scheduled event is erased, because the event scheduler is reset when the emulator is powered on. To make a long story short: The disk needs to be inserted after the emulator has been launched. Hence, moving the addMedia() call below the try-catch block fixed the issue.

bluecursor commented 1 year ago

This error seems to halter the ability to change Control Emulation Keys. Only by closing and reopening V64 resolves it.