@@ -78,7 +78,13 @@ extension AgoraMetalRender: AgoraVideoSinkProtocol {
7878 }
7979
8080 func shouldDispose( ) {
81+ _ = semaphore. wait ( timeout: . distantFuture)
8182 textures = nil
83+ vertexBuffer = nil
84+ #if os(macOS) || (os(iOS) && (!arch(i386) && !arch(x86_64)))
85+ metalView. delegate = nil
86+ #endif
87+ semaphore. signal ( )
8288 }
8389
8490 func bufferType( ) -> AgoraVideoBufferType {
@@ -108,7 +114,7 @@ extension AgoraMetalRender: AgoraVideoSinkProtocol {
108114 videoSize: size,
109115 viewSize: viewSize) {
110116 let byteLength = 16 * MemoryLayout. size ( ofValue: renderedCoordinates [ 0 ] )
111- vertexBuffer = device? . makeBuffer ( bytes: renderedCoordinates, length: byteLength, options: [ ] )
117+ vertexBuffer = device? . makeBuffer ( bytes: renderedCoordinates, length: byteLength, options: [ . storageModeShared ] )
112118 }
113119
114120 if let yTexture = texture ( pixelBuffer: pixelBuffer, textureCache: textureCache, planeIndex: 0 , pixelFormat: . r8Unorm) ,
@@ -196,18 +202,16 @@ extension AgoraMetalRender: MTKViewDelegate {
196202 }
197203
198204 _ = semaphore. wait ( timeout: . distantFuture)
199- autoreleasepool {
200- guard let textures = textures, let device = device,
201- let commandBuffer = commandQueue? . makeCommandBuffer ( ) else {
202- _ = semaphore. signal ( )
205+ guard let textures = textures, let device = device,
206+ let commandBuffer = commandQueue? . makeCommandBuffer ( ) , let vertexBuffer = vertexBuffer else {
207+ semaphore. signal ( )
203208 return
204- }
205-
206- render ( textures: textures, withCommandBuffer: commandBuffer, device: device)
207209 }
210+
211+ render ( textures: textures, withCommandBuffer: commandBuffer, device: device, vertexBuffer: vertexBuffer)
208212 }
209213
210- private func render( textures: [ MTLTexture ] , withCommandBuffer commandBuffer: MTLCommandBuffer , device: MTLDevice ) {
214+ private func render( textures: [ MTLTexture ] , withCommandBuffer commandBuffer: MTLCommandBuffer , device: MTLDevice , vertexBuffer : MTLBuffer ) {
211215 guard let currentRenderPassDescriptor = metalView. currentRenderPassDescriptor,
212216 let currentDrawable = metalView. currentDrawable,
213217 let renderPipelineState = renderPipelineState,
0 commit comments