From 19be9a174ae308f52531c263bf9ddacdde95a44f Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Wed, 22 Jul 2020 22:59:46 +0900 Subject: [PATCH] fix: occasional crash when focusing a window (closes #459) --- src/logic/Window.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/logic/Window.swift b/src/logic/Window.swift index c2e87b06..d6244720 100644 --- a/src/logic/Window.swift +++ b/src/logic/Window.swift @@ -166,8 +166,11 @@ class Window { memset(&bytes1[0x20], 0xFF, 0x10) memcpy(&bytes2[0x3c], &cgWindowId, MemoryLayout.size) memset(&bytes2[0x20], 0xFF, 0x10) - SLPSPostEventRecordTo(&psn_, &(UnsafeMutablePointer(mutating: UnsafePointer(bytes1)).pointee)) - SLPSPostEventRecordTo(&psn_, &(UnsafeMutablePointer(mutating: UnsafePointer(bytes2)).pointee)) + [bytes1, bytes2].forEach { bytes in + _ = bytes.withUnsafeBufferPointer() { pointer in + SLPSPostEventRecordTo(&psn_, &UnsafeMutablePointer(mutating: pointer.baseAddress)!.pointee) + } + } } // for some windows (e.g. Slack), the AX API doesn't return a title; we try CG API; finally we resort to the app name