Post

Replies

Boosts

Views

Activity

Reply to Crash when set CAMetalLayer.presentsWithTransaction=true in background thread
Here is the crash stack trace Application Specific Information: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.' Last Exception Backtrace: 0 CoreFoundation 0x000000018c8fde48 0x000000018c8f4000 + 40520 1 libobjc.A.dylib 0x0000000185bc78d8 0x0000000185bb0000 + 96472 2 CoreAutoLayout 0x00000001a9304e84 0x00000001a92f7000 + 56964 3 CoreAutoLayout 0x00000001a92fb9b4 0x00000001a92f7000 + 18868 4 CoreAutoLayout 0x00000001a92fb8e4 0x00000001a92f7000 + 18660 5 CoreAutoLayout 0x00000001a92fb670 0x00000001a92f7000 + 18032 6 UIKitCore 0x000000018eacf284 0x000000018eac9000 + 25220 7 UIKitCore 0x000000018eacd860 0x000000018eac9000 + 18528 8 QuartzCore 0x000000018dfa0b0c 0x000000018df97000 + 39692 9 QuartzCore 0x000000018dfb41c0 0x000000018df97000 + 119232 10 QuartzCore 0x000000018dfc5534 0x000000018df97000 + 189748 11 QuartzCore 0x000000018dffa930 0x000000018df97000 + 407856 12 QuartzCore 0x000000018dfe3bb4 0x000000018df97000 + 314292 13 CoreFoundation 0x000000018c985d40 0x000000018c8f4000 + 597312 14 CoreFoundation 0x000000018c90e290 0x000000018c8f4000 + 107152 15 CoreFoundation 0x000000018c96fc60 0x000000018c8f4000 + 506976 16 CoreFoundation 0x000000018c974ec0 0x000000018c8f4000 + 528064 17 Flutter 0x000000010be19acc 0x000000010bb2c000 + 3070668 18 Flutter 0x000000010be195c8 0x000000010bb2c000 + 3069384 19 libsystem_pthread.dylib 0x00000001da9866cc 0x00000001da985000 + 5836 20 libsystem_pthread.dylib 0x00000001da985ba4 0x00000001da985000 + 2980 Binary Images: 0x000000010bb2c000 - 0x000000010c30bfff Flutter arm64 <4c4c448455553144a17746f7af31d4ec> /private/var/containers/Bundle/Application/B2924516-9912-465A-A74E-74DB5A6026F7/Runner.app/Frameworks/Flutter.framework/Flutter 0x0000000185bb0000 - 0x0000000185bf3e1f libobjc.A.dylib arm64-unknown <d6ecfb730ca23a21a3a919e450d3b49c> /usr/lib/libobjc.A.dylib 0x000000018c8f4000 - 0x000000018ccd9fff CoreFoundation arm64-unknown <725e49f4653b39bf9a7a8a3250911ecb> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 0x000000018df97000 - 0x000000018e2f5fff QuartzCore arm64-unknown <e0e47b5d2805361d88c4875002b0244d> /System/Library/Frameworks/QuartzCore.framework/QuartzCore 0x000000018eac9000 - 0x00000001902b4fff UIKitCore arm64-unknown <59cbc9b530ae396ea269a986640001bc> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore 0x00000001a92f7000 - 0x00000001a933ffff CoreAutoLayout arm64-unknown <e96465db77983db5bc5851e367946a04> /System/Library/PrivateFrameworks/CoreAutoLayout.framework/CoreAutoLayout 0x00000001da985000 - 0x00000001da990fff libsystem_pthread.dylib arm64-unknown <f2ba7ec0f75a3345b4f6f7da4979b902> /usr/lib/system/libsystem_pthread.dylib
Jan ’23
Reply to CAMetalLayer.nextDrawable() is very time-consuming, take 5ms-12ms
Hi, Here is the code I use to measure: class TestVC: UIViewController { let metalLayer:CAMetalLayer = CAMetalLayer() var displayLink:CADisplayLink! var thread:Thread! override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = .red let scale = UIScreen.main.scale metalLayer.frame = self.view.bounds metalLayer.drawableSize = CGSize(width: self.view.frame.width * scale, height: self.view.frame.height * scale) self.view.layer.addSublayer(metalLayer) self.addDisplayLinkInTask() } func addDisplayLinkInTask() { self.thread = Thread(block: { RunLoop.current.add(NSMachPort(), forMode: .common) RunLoop.current.run() }) self.thread.name = "sub thread" self.thread.start() self.perform(#selector(addDisplayLink), on: thread, with: nil, waitUntilDone: false) } @objc func addDisplayLink() { self.displayLink = CADisplayLink(target: self, selector: #selector(onDisplayLink)) if #available(iOS 15.0, *) { self.displayLink.preferredFrameRateRange = .init(minimum: 60, maximum: 120, preferred: 120) } else { self.displayLink.preferredFramesPerSecond = 120 } self.displayLink.add(to: .current, forMode: .common) } @objc private func onDisplayLink() { let startTime = CACurrentMediaTime() let frameDrawable = metalLayer.nextDrawable()! let timeUsed = CACurrentMediaTime() - startTime // If time used to get next drawble over 3ms, // we print it here to indicate this method take much time! if (timeUsed > 0.003) { print("CAMetalLayer.nextDrawable take much time!! -> \(String(format: "%.2f", timeUsed * 1000)) ms") } frameDrawable.present() } }
Dec ’22
Reply to How to pass custom object in MTAudioProcessingTapCallbacks?
let tapInit: MTAudioProcessingTapInitCallback = {       (tap, clientInfo, tapStorageOut) in       tapStorageOut.pointee = clientInfo     }  var callback = MTAudioProcessingTapCallbacks(version: kMTAudioProcessingTapCallbacksVersion_0, clientInfo:UnsafeMutableRawPointer(Unmanaged.passUnretained(self.engine).toOpaque()), init: tapInit, finalize: tapFinalize, prepare: tapPrepare, unprepare: tapUnprepare) { tap, numberFrames, flags, bufferListInOut, numberFramesOut, flagsOut in               guard MTAudioProcessingTapGetSourceAudio(tap, numberFrames, bufferListInOut, flagsOut, nil, numberFramesOut) == noErr else {         preconditionFailure()       }       let storage = MTAudioProcessingTapGetStorage(tap)       let engine = Unmanaged<Engine>.fromOpaque(storage).takeUnretainedValue()       engine.render(bufferPtr: bufferListInOut)            }
Nov ’21