dirkwhoffmann / vAmiga

vAmiga is a user-friendly Amiga 500, 1000, 2000 emulator for macOS
https://dirkwhoffmann.github.io/vAmiga
Other
291 stars 24 forks source link

Saving machine causes a crash #833

Open MaddTheSane opened 4 days ago

MaddTheSane commented 4 days ago

If you go to Machine -> Save, vAmiga crashes. I seems to crash here: https://github.com/dirkwhoffmann/vAmiga/blob/2b8e4c1899fed0c6a4c47c080daf2e9a8f3f3da1/Emulator/Base/CoreComponent.cpp#L144

The only thing I can think that might be wrong is that the << operator might not be overridden.

dirkwhoffmann commented 4 days ago

Oops, the most fundamental functionality is broken in 2.6 🙄. Thanks for reporting!

The culprit is the objC wrapper (which will hopefully be obsolete one day). It juggles with void pointers, and I have introduced several new wrappers with the new SW architecture (coming from VirtualC64).

To get things right, I need to cast to AmigaAPI in this function (instead of Amiga):

+ (instancetype)makeWithAmiga:(AmigaProxy *)proxy
{
    AmigaAPI *amiga = (AmigaAPI *)proxy->obj;

    amiga->suspend();
    Snapshot *snapshot = new Snapshot(*(amiga->amiga));
    amiga->resume();

    return [self make:snapshot];
}

However, there is another bug. The emulator resets when loading a snapshot with Open.... I need to check if the same happens in VirtualC64.

Personally, I always use drag-and-drop instead of Open... from the menu, which is why I didn't recognize this bug.

MaddTheSane commented 4 days ago

I tried to migrate vAmiga to allow Swift to import C++, but the generated Swift header…

It seems like it forgot about Objective-C enums, as well as exporting the Swift logging functions to C++ (which messes with some macros):

In file included from /Users/cwbetts/makestuff/vAmiga/Proxy/EmulatorProxy.mm:14:
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:791:76: error: expected a type
- (nonnull instancetype)initWithContentRect:(NSRect)contentRect styleMask:(StyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag OBJC_DESIGNATED_INITIALIZER;
                                                                           ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:1908:4: error: expected a type
- (PresentationOptions)window:(NSWindow * _Nonnull)window willUseFullScreenPresentationOptions:(PresentationOptions)proposedOptions SWIFT_WARN_UNUSED_RESULT;
   ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:1908:97: error: expected a type
- (PresentationOptions)window:(NSWindow * _Nonnull)window willUseFullScreenPresentationOptions:(PresentationOptions)proposedOptions SWIFT_WARN_UNUSED_RESULT;
                                                                                                ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:2215:76: error: expected a type
- (nonnull instancetype)initWithContentRect:(NSRect)contentRect styleMask:(StyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag OBJC_DESIGNATED_INITIALIZER;
                                                                           ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:2400:76: error: expected a type
- (nonnull instancetype)initWithContentRect:(NSRect)contentRect styleMask:(StyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag OBJC_DESIGNATED_INITIALIZER;
                                                                           ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:2875:3: warning: '_Alignas' is a C11 extension [-Wc11-extensions]
  _Alignas(8) char _storage[8];
  ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:2941:3: warning: '_Alignas' is a C11 extension [-Wc11-extensions]
  _Alignas(8) char _storage[16];
  ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:2956:3: warning: '_Alignas' is a C11 extension [-Wc11-extensions]
  _Alignas(8) char _storage[16];
  ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:7289:3: warning: '_Alignas' is a C11 extension [-Wc11-extensions]
  _Alignas(1) char _storage[1];
  ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:7676:25: error: expected unqualified-id
SWIFT_INLINE_THUNK void debug(swift::Int enable, const swift::String& msg, const swift::String& path, const swift::String& function, swift::Int line) noexcept SWIFT_SYMBOL("s:6vAmiga5debug__4path8function4lineySi_S3SSitF") {
                        ^
In file included from /Users/cwbetts/makestuff/vAmiga/Proxy/EmulatorProxy.mm:12:
In file included from /Users/cwbetts/makestuff/vAmiga/Emulator/Components/Amiga.h:13:
In file included from /Users/cwbetts/makestuff/vAmiga/Emulator/Base/CoreComponent.h:14:
/Users/cwbetts/makestuff/vAmiga/Emulator/Base/CoreObject.h:77:36: note: expanded from macro 'debug'
#define debug(enable, format, ...) \
                                   ^
In file included from /Users/cwbetts/makestuff/vAmiga/Proxy/EmulatorProxy.mm:14:
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:7676:151: error: expected unqualified-id
SWIFT_INLINE_THUNK void debug(swift::Int enable, const swift::String& msg, const swift::String& path, const swift::String& function, swift::Int line) noexcept SWIFT_SYMBOL("s:6vAmiga5debug__4path8function4lineySi_S3SSitF") {
                                                                                                                                                      ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:7686:1: warning: 'transparent_stepping' attribute only applies to functions [-Wignored-attributes]
SWIFT_INLINE_THUNK void warn(const swift::String& msg, const swift::String& path, const swift::String& function, swift::Int line) noexcept SWIFT_SYMBOL("s:6vAmiga4warn_4path8function4lineySS_S2SSitF") {
^
In file included from /Users/cwbetts/makestuff/vAmiga/Proxy/EmulatorProxy.mm:14:
In file included from /Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:2496:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/../../../swift/swiftToCxx/_SwiftCxxInteroperability.h:53:10: note: expanded from macro 'SWIFT_INLINE_THUNK'
  inline SWIFT_INLINE_THUNK_ATTRIBUTES SWIFT_INLINE_THUNK_USED_ATTRIBUTE
         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/../../../swift/swiftToCxx/_SwiftCxxInteroperability.h:33:18: note: expanded from macro 'SWIFT_INLINE_THUNK_ATTRIBUTES'
  __attribute__((transparent_stepping))
                 ^
In file included from /Users/cwbetts/makestuff/vAmiga/Proxy/EmulatorProxy.mm:14:
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:7686:25: error: variable has incomplete type 'void'
SWIFT_INLINE_THUNK void warn(const swift::String& msg, const swift::String& path, const swift::String& function, swift::Int line) noexcept SWIFT_SYMBOL("s:6vAmiga4warn_4path8function4lineySS_S2SSitF") {
                        ^
In file included from /Users/cwbetts/makestuff/vAmiga/Proxy/EmulatorProxy.mm:12:
In file included from /Users/cwbetts/makestuff/vAmiga/Emulator/Components/Amiga.h:13:
In file included from /Users/cwbetts/makestuff/vAmiga/Emulator/Base/CoreComponent.h:14:
/Users/cwbetts/makestuff/vAmiga/Emulator/Base/CoreObject.h:71:27: note: expanded from macro 'warn'
#define warn(format, ...) \
                          ^
In file included from /Users/cwbetts/makestuff/vAmiga/Proxy/EmulatorProxy.mm:14:
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:7686:30: error: expected ')'
SWIFT_INLINE_THUNK void warn(const swift::String& msg, const swift::String& path, const swift::String& function, swift::Int line) noexcept SWIFT_SYMBOL("s:6vAmiga4warn_4path8function4lineySS_S2SSitF") {
                             ^
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:7686:25: note: to match this '('
SWIFT_INLINE_THUNK void warn(const swift::String& msg, const swift::String& path, const swift::String& function, swift::Int line) noexcept SWIFT_SYMBOL("s:6vAmiga4warn_4path8function4lineySS_S2SSitF") {
                        ^
In file included from /Users/cwbetts/makestuff/vAmiga/Proxy/EmulatorProxy.mm:12:
In file included from /Users/cwbetts/makestuff/vAmiga/Emulator/Components/Amiga.h:13:
In file included from /Users/cwbetts/makestuff/vAmiga/Emulator/Base/CoreComponent.h:14:
/Users/cwbetts/makestuff/vAmiga/Emulator/Base/CoreObject.h:72:8: note: expanded from macro 'warn'
fprintf(stderr, "Warning: " format __VA_OPT__(,) __VA_ARGS__);
       ^
In file included from /Users/cwbetts/makestuff/vAmiga/Proxy/EmulatorProxy.mm:14:
/Users/cwbetts/Library/Developer/Xcode/DerivedData/vAmiga-cxcypwtwufssyghiisudgbjvjmhq/Build/Intermediates.noindex/vAmiga.build/Debug/vAmiga.build/DerivedSources/vAmiga-Swift.h:7686:131: error: expected unqualified-id
SWIFT_INLINE_THUNK void warn(const swift::String& msg, const swift::String& path, const swift::String& function, swift::Int line) noexcept SWIFT_SYMBOL("s:6vAmiga4warn_4path8function4lineySS_S2SSitF") {
                                                                                                                                  ^
5 warnings and 10 errors generated.

You can find my first attempt here: https://github.com/MaddTheSane/vAmiga/tree/swiftxx

dirkwhoffmann commented 4 days ago

I tried the same a couple of weeks ago with similar error messages. Curiously, it works for VirtualC64. Thus, my plan is to clean up all APIs first (as part of porting VirtualC64's new emulator architecture to vAmiga) and then try to enable C++ interoperability again.

BTW, I only utilize C++ interoperability in VirtualC64 to include native C++ header files at the moment, which allowed me to eliminate most #ifdef statements that check for C++. However, I am still using the ObjC proxy, because calling C++ functions directly did not work out for me as expected. The whole compile process slowed down massively. I've got the impression that Swift/C++ interoperability is in an early beta state. Thus, I'll wait for it to mature a bit before I try to elminate the ObjC proxy for good.