Skip to content

Commit 7dac34c

Browse files
committed
fix(RaspberryPi): fix the issue on an actual device
1 parent 7cc7e27 commit 7dac34c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Sources/RaspberryPi/Framebuffer.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,22 @@ package struct Framebuffer<Depth: UnsignedInteger>: ~Copyable {
8787
// success?
8888
guard mboxCall(ch: .property) else { fatalError() }
8989

90-
let pixelCount = unsafe Int(mbox.29) / MemoryLayout<Depth>.stride
90+
let pixelCount = unsafe Int(mbox.10 &* mbox.11)
91+
let byteCount = unsafe mbox.29
92+
let gpuAddr = unsafe mbox.28
9193

9294
guard
9395
unsafe mbox.20 == depth,
94-
unsafe mbox.28 != 0, // pointer is not null
95-
unsafe pixelCount == mbox.10 &* mbox.11
96+
gpuAddr != 0,
97+
byteCount >= pixelCount &* MemoryLayout<Depth>.size
9698
else { fatalError() }
9799

98100
self.width = unsafe mbox.10
99101
self.height = unsafe mbox.11
100102
// swift-format-ignore: NeverForceUnwrap
101103
self.pixelOrder = unsafe .init(rawValue: mbox.24)!
102104
// GPU address to ARM address
103-
let addr = unsafe UInt(mbox.28 & 0x3FFF_FFFF)
105+
let addr = UInt(gpuAddr & 0x3FFF_FFFF)
104106
// swift-format-ignore: NeverForceUnwrap
105107
unsafe self.baseAddress = UnsafeMutableRawPointer(bitPattern: addr)!
106108
.bindMemory(to: Depth.self, capacity: pixelCount)

0 commit comments

Comments
 (0)