dirkwhoffmann / virtualc64

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

Open a Disk Image from menu crashes VirtualC64 (Only in alpha release) #464

Closed Alessandro1970 closed 5 years ago

Alessandro1970 commented 5 years ago

Hi, if I try to open a disk image from the menu (FILE --> OPEN --> .d64 image) the VirtualC64 crashes.

This is the report of the crash : report.txt.zip

schermata 2018-11-13 alle 23 03 28
dirkwhoffmann commented 5 years ago

Hmmm, I didn't manage to reproduce that. Does it occur all the time on your machine or only with a specific D64 image? 🤔

Alessandro1970 commented 5 years ago

No, it hangs with .d64 , .crt ...with all files. In this example I tried to load logo.d64 from the desktop: report2.txt.zip

schermata 2018-11-19 alle 21 21 07
Alessandro1970 commented 5 years ago

This problem occurs with VirtualC64 alpha 3 and alpha 4 If I use 3.1.1 or 3.0.1 version it doesn't happen

mortinus commented 5 years ago

It crashes on my mac too. (alpha 4)

rossimariolee commented 5 years ago

If "Open" is selected from menu and than you try to load a .d64, a .crt or a .tap image VirtualC64 (alpha 4) quit immediatly.

UgoCaneFifone commented 5 years ago

It crashes on my MBP too (the version 3.1.1 worked fine, it is something changed in the alpha, I do not remeber alpha2 but alpha 3 and 4 crash)

dirkwhoffmann commented 5 years ago

Found it. When the emulator starts, macOS calls the following methods (besides others):

awakeFromNib()
windowDidLoad()
windowDidBecomeMain()

Originally, the AudioEngine was initialized in windowDidLoad and used in windowDidBecomeMain. However, it seems that the function order may vary. I.e., if a second window opens, the following order is possible:

awakeFromNib()
windowDidBecomeMain()
windowDidLoad()

Hence, the AudioEngine is used before it is initialized which crashes the emulator.

It didn't crash in 3.1.1, because AudioEngine initialization was still implemented in Objective-C. I notices that a couple of weeks ago and migrated it to Swift (with the bug included).

I've moved to initialization to awakeFromNib() which seems to a safe place. The crash should be gone in alpha 5:

http://www.dirkwhoffmann.de/virtualc64/VirtualC64_3.2alpha5.zip

BTW, I assembled together a small tutorial how to get debug information in Xcode when the emulator crashes. Sometimes (as in this case), the crash report alone does not contain enough information to debug. The tutorial (which shows how to debug the bug we're talking about) is available on GitQ in the forum:

https://gitq.com/dirkwhoffmann/virtualc64/topics/8/how-do-i-report-a-crash

If you are eager to walk through the tutorial and think that it's not clear enough at some point, please let me know.