From 8ba408ea2000d2c07174bff1b2ee50aa5ff76a8d Mon Sep 17 00:00:00 2001 From: Daniele Cattaneo Date: Fri, 14 Jun 2019 23:56:19 +0200 Subject: [PATCH] fix: apparently the length of the buffer must be aligned to 4096 bytes as well --- Source/OEPixelBuffer.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/OEPixelBuffer.m b/Source/OEPixelBuffer.m index ea532d4..40c89c2 100644 --- a/Source/OEPixelBuffer.m +++ b/Source/OEPixelBuffer.m @@ -127,15 +127,16 @@ BufferOption BufferOptionMustCopy(BufferOption o) { _srcBytesPerRow = bytesPerRow; _sourceSize = CGSizeMake(bytesPerRow / OEMTLPixelFormatToBPP(format), height); [self setFormat:format]; - - if ((uintptr_t)pointer % 4096 == 0) { + + NSUInteger length = height * bytesPerRow; + if (((uintptr_t)pointer % 4096 == 0) && (length % 4096 == 0)) { _options |= BufferOptionNoCopy; - _srcBuffer = [_device newBufferWithBytesNoCopy:pointer length:height * bytesPerRow options:MTLResourceStorageModeShared deallocator:nil]; + _srcBuffer = [_device newBufferWithBytesNoCopy:pointer length:length options:MTLResourceStorageModeShared deallocator:nil]; } else { _options &= ~BufferOptionNoCopy; _buffer = pointer; - _bufferLenBytes = bytesPerRow * height; - _srcBuffer = [_device newBufferWithLength:height * bytesPerRow options:MTLResourceStorageModeShared]; + _bufferLenBytes = length; + _srcBuffer = [_device newBufferWithLength:length options:MTLResourceStorageModeShared]; }