Skip to content

Commit

Permalink
Bugfix: Make sure to only call bufferBytesPerRow on 10.12 and newer
Browse files Browse the repository at this point in the history
  • Loading branch information
peterb180369 committed Dec 4, 2018
1 parent 7147a73 commit 6c4fd17
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions BXSwiftUtils/Metal/MTLTexture+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ public extension MTLTexture
public var recommendedRowBytes:Int
{
let width = self.width
let rowBytes = self.bufferBytesPerRow
return rowBytes > 0 ? rowBytes : ((width * 4 + 15) / 16) * 16
var rowBytes = ((width * 4 + 15) / 16) * 16

if #available(macOS 10.12,*)
{
let rb = self.bufferBytesPerRow
if rb > 0 { rowBytes = rb }
}

return rowBytes
}


Expand All @@ -46,7 +53,7 @@ public extension MTLTexture

guard w > 0 && h > 0 && rowBytes > 0 else { return nil }

// Allocate memory
// Allocate buffer

let size = rowBytes * h
var buffer = [UInt8](repeating:0,count:size)
Expand Down

0 comments on commit 6c4fd17

Please sign in to comment.