Skip to content

Commit 71e31cf

Browse files
committed
use UnsafeMutablePointer.allocate instead of [UInt8]
1 parent aab1009 commit 71e31cf

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Sources/FlutterSwift/Client/FlutterTexture.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,28 @@ private func _releaseAnyObject(_ anyObjectPtr: UnsafeMutableRawPointer?) {
4343
}
4444

4545
public class FlutterPixelBuffer {
46-
public var buffer: [UInt8]
46+
public var buffer: UnsafeMutablePointer<UInt8>
4747
public var width: Int
4848
public var height: Int
4949

5050
private var _desktopPixelBuffer = FlutterDesktopPixelBuffer()
5151

5252
public init(width: Int, height: Int) {
53-
buffer = [UInt8](repeating: 0, count: width * height)
53+
buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: width * height)
54+
buffer.initialize(repeating: 0, count: width * height)
5455
self.width = width
5556
self.height = height
5657
}
5758

59+
deinit {
60+
buffer.deallocate()
61+
}
62+
5863
fileprivate func getDesktopPixelBufferTextureConfig(
5964
width: Int,
6065
height: Int
6166
) -> UnsafePointer<FlutterDesktopPixelBuffer> {
62-
buffer.withUnsafeBufferPointer { _desktopPixelBuffer.buffer = $0.baseAddress! }
67+
_desktopPixelBuffer.buffer = UnsafePointer(buffer)
6368
_desktopPixelBuffer.width = self.width
6469
_desktopPixelBuffer.height = self.height
6570
_desktopPixelBuffer.release_context = _retainAnyObject(self)

0 commit comments

Comments
 (0)