diff --git a/Sources/SwiftGodot/Core/GenericSignal.swift b/Sources/SwiftGodot/Core/GenericSignal.swift index 821bb20ae..8df584ccb 100644 --- a/Sources/SwiftGodot/Core/GenericSignal.swift +++ b/Sources/SwiftGodot/Core/GenericSignal.swift @@ -95,7 +95,9 @@ public class GenericSignal { args.append(Variant(arg)) } let result = target.emitSignalWithArguments(args) - return GodotError(rawValue: Int64(result)!)! + guard let result else { return .ok } + guard let errorCode = Int(result) else { return .ok } + return GodotError(rawValue: Int64(errorCode))! } /// You can await this property to wait for the signal to be emitted once. diff --git a/Sources/SwiftGodot/Core/RawCall.swift b/Sources/SwiftGodot/Core/RawCall.swift index a4714d9d2..f0c5be29e 100644 --- a/Sources/SwiftGodot/Core/RawCall.swift +++ b/Sources/SwiftGodot/Core/RawCall.swift @@ -6,7 +6,7 @@ extension Object { /// All input arguments must be marshaled into `Variant`s. /// The result is a `Variant` that must be unmarshaled into the expected type. @discardableResult /* discardable per discardableList: Object, emit_signal */ - final func rawCall(_ p_method_bind: GDExtensionMethodBindPtr, arguments: [Variant]) -> Variant { + final func rawCall(_ p_method_bind: GDExtensionMethodBindPtr, arguments: [Variant]) -> Variant? { var _result: Variant.ContentType = Variant.zero // A temporary allocation containing pointers to `Variant.ContentType` of marshaled arguments withUnsafeTemporaryAllocation(of: UnsafeRawPointer?.self, capacity: arguments.count) { pArgsBuffer in @@ -33,12 +33,12 @@ extension Object { } } - return Variant(copying: _result) + return Variant(takingOver: _result) } /// Non-variadic variation on the emitSignal method. /// Used by GenericSignal. - public final func emitSignalWithArguments(_ arguments: [Variant]) -> Variant { + public final func emitSignalWithArguments(_ arguments: [Variant]) -> Variant? { return rawCall(Object.method_emit_signal, arguments: arguments) }