Crash on Nintendo Switch
A modern MTP device management tool for macOS.
Brought to you by:
neighbor-z
Originally created by: bexonpak
Operating on Nintendo Switch:
System Settings -> Data Management -> Manage Screenshots and Videos -> Copy to a Computer via USB Connection
Log:
private func int64FromAny(_ any: Any?) -> Int64? {
switch any {
case let v as Int64: return v
case let v as UInt64: return Int64(v) <- Thread 1: Fatal error: Not enough bits to represent the passed value
case let v as Int: return Int64(v)
case let v as Double: return Int64(v)
case let v as Float: return Int64(v)
case let v as NSNumber: return v.int64Value
default: return nil
}
}
:::bash
(lldb) po v
18446744073709551615
After switching to the following approach, it no longer crashes:
case let v as UInt64: return Int64(exactly: v)
The value 18446744073709551615 (UInt64.max) returned by the Nintendo Switch usually indicates an "invalid/unset" marker value, but returning it as such would break the total capacity calculation.
Originally posted by: Neighbor-Z
Hello @bexonpak,
Thank you for bringing this to attention. I really want the software to be stable across most MTP devices, but unfortunately I don't actually own a Nintendo Switch and I am not familiar with the technical details of that device.
Based on your description, I’m not sure if the Switch just doesn't provide valid total capacity data for storage, or is it just cannot be retrieved correctly through current method? If it’s the former, then the fix
case let v as UInt64: return Int64(exactly: v)would be fine. Otherwise, things would be more complicated and tie into the backend.I'm wondering if you are willing to checkout and contribute to the related repos https://github.com/Neighbor-Z/go-mtpx/ and https://github.com/Neighbor-Z/go-mtpfs/ which are the backend logics. I'm always willing to extend/enhance the support SwiftMTP could provide.