diff --git a/OpenParsec/MainView.swift b/OpenParsec/MainView.swift index a6b5ad6e..285d522e 100644 --- a/OpenParsec/MainView.swift +++ b/OpenParsec/MainView.swift @@ -674,6 +674,11 @@ struct MainView: View { if let window = UIApplication.shared.connectedScenes.compactMap({ $0 as? UIWindowScene }).flatMap({ $0.windows }).first(where: { $0.isKeyWindow }) { let scale = window.screen.nativeScale ParsecResolution.updateClientResolution(width: Int(window.bounds.width * scale), height: Int(window.bounds.height * scale)) + } else { + // no key window yet on a launch reconnect, without this it asks the host for 3840x2160 + let screen = UIScreen.main + let scale = screen.nativeScale + ParsecResolution.updateClientResolution(width: Int(screen.bounds.width * scale), height: Int(screen.bounds.height * scale)) } pollTimer?.invalidate() diff --git a/OpenParsec/ParsecMetalRenderer.swift b/OpenParsec/ParsecMetalRenderer.swift index 5715f321..6237a5b9 100644 --- a/OpenParsec/ParsecMetalRenderer.swift +++ b/OpenParsec/ParsecMetalRenderer.swift @@ -28,7 +28,7 @@ private let frameCallback: ParsecFrameCallback = { frame, image, opaque in extension ParsecFrame { var isWholeNV12: Bool { let w = Int(width), h = Int(height), stride = Int(fullWidth), rows = Int(fullHeight) - return format == FORMAT_NV12 && w > 0 && h > 0 && stride >= w && rows >= h && Int(size) >= stride * rows + stride * ((h + 1) / 2) + return format == FORMAT_NV12 && w > 0 && h > 0 && stride >= 2 * ((w + 1) / 2) && rows >= h && Int(size) >= stride * rows + stride * ((h + 1) / 2) } } diff --git a/OpenParsec/ParsecSDKBridge.swift b/OpenParsec/ParsecSDKBridge.swift index ab1d0a0e..11658ac2 100644 --- a/OpenParsec/ParsecSDKBridge.swift +++ b/OpenParsec/ParsecSDKBridge.swift @@ -212,8 +212,10 @@ class ParsecSDKBridge: ParsecService { func getStatusEx(_ pcs: inout ParsecClientStatus) -> ParsecStatus { let ans = ParsecClientGetStatus(_parsec, &pcs) - self.hostHeight = Float(pcs.decoder.0.height) - self.hostWidth = Float(pcs.decoder.0.width) + if pcs.decoder.0.width > 0 && pcs.decoder.0.height > 0 { + self.hostHeight = Float(pcs.decoder.0.height) + self.hostWidth = Float(pcs.decoder.0.width) + } // the teardown release may not have made it out, this one goes over a socket we know is live if ans == PARSEC_OK && !didReleaseOnConnect { @@ -373,6 +375,10 @@ class ParsecSDKBridge: ParsecService { let size = event.cursor.size let width = event.cursor.width let height = event.cursor.height + guard width > 0, height > 0, Int(size) >= Int(width) * Int(height) * 4 else { + ParsecFree(pointer) + return + } mouseInfo.cursorWidth = Int(width) mouseInfo.cursorHeight = Int(height) @@ -388,9 +394,8 @@ class ParsecSDKBridge: ParsecService { let render: CGColorRenderingIntent = CGColorRenderingIntent.defaultIntent let rgbColorSpace = CGColorSpaceCreateDeviceRGB() let bitmapInfo: CGBitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.last.rawValue) - let providerRef: CGDataProvider? = CGDataProvider(data: NSData(bytes: pointer, length: Int(size))) - let cgimage: CGImage? = CGImage(width: Int(width), height: Int(height), bitsPerComponent: 8, bitsPerPixel: 32, bytesPerRow: Int(width) * elmentLength, space: rgbColorSpace, bitmapInfo: bitmapInfo, provider: providerRef!, decode: nil, shouldInterpolate: true, intent: render) - if cgimage != nil { + if let providerRef = CGDataProvider(data: NSData(bytes: pointer, length: Int(size))), + let cgimage = CGImage(width: Int(width), height: Int(height), bitsPerComponent: 8, bitsPerPixel: 32, bytesPerRow: Int(width) * elmentLength, space: rgbColorSpace, bitmapInfo: bitmapInfo, provider: providerRef, decode: nil, shouldInterpolate: true, intent: render) { mouseInfo.cursorImg = cgimage } ParsecFree(pointer)