MTLBuffer content returns NULL although shared

My MTLBuffer is created with the standard MTLResourceStorageModeShared option and I get the pointer to the system memory using the contents method. This works fine on Catalina and Big Sur but my testers on Sierra and High Sierra report that the application crashes. Evaluating the crash reports tell me that the contents method returns a Null pointer.

What am I missing?

Code Block
typedef struct KaroMetalLineData KaroMetalLineData;
struct KaroMetalLineData{
 packed_float2 p1;
 packed_float2 p2;
 packed_float4 color;
 float arg1;
 float arg2;
 float blend;
 int32_t type;
};
...
   size_t inputBufferSize = sizeof(KaroMetalLineData) * lineCount; /* is guaranteed to be not zero! */
id<MTLBuffer> lineInputBuffer = [metal->device newBufferWithLength:inputBufferSize options:(MTLResourceOptions)0];
KaroMetalLineData* localInput = [lineInputBuffer contents];
  memcpy(localInput, someSource, inputBufferSize); /* someSource is guaranteed to exist and have enough space*/
...

Replies

Looks like there is another possibility what could go wrong. As objective-C allows to send messages to nil objects, the error could be that the buffer itself is nil. Which could mean that the device is nil which could mean that the metal Layer is nil. So I changed to a hosted layer setup where in my view, I explicitely create a layer and assign it to the view and then set wantsLayer to true (see documentation of wantsLayer). Let's hope for the best that this works.

But why is this only happening on Sierra and High Sierra? Guess it is not that important.
Did you check if MTLResourceStorageModeShared is supported on Sierra and High Sierra on the GPU your testers are using?