From e1b3c8afd574e9da9638103646792d75bfee7394 Mon Sep 17 00:00:00 2001 From: Jacul Date: Sun, 5 Jul 2026 22:52:41 -0400 Subject: [PATCH] metal: check MTLBuffer allocations for nil before using their contents. --- src/render/metal/SDL_render_metal.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m index 0b2ddf710d..f718fcc9f8 100644 --- a/src/render/metal/SDL_render_metal.m +++ b/src/render/metal/SDL_render_metal.m @@ -1606,6 +1606,9 @@ static bool SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, c if (statecache->shader_constants_dirty || SDL_memcmp(shader_constants, &statecache->shader_constants, sizeof(*shader_constants)) != 0) { id mtlbufconstants = [data.mtldevice newBufferWithLength:sizeof(*shader_constants) options:MTLResourceStorageModeShared]; + if (mtlbufconstants == nil) { + return SDL_OutOfMemory(); + } mtlbufconstants.label = @"SDL shader constants data"; SDL_memcpy([mtlbufconstants contents], shader_constants, sizeof(*shader_constants)); [data.mtlcmdencoder setFragmentBuffer:mtlbufconstants offset:0 atIndex:0]; @@ -1776,6 +1779,9 @@ static bool METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd * practices guide recommends this approach for streamed vertex data. */ mtlbufvertex = [data.mtldevice newBufferWithLength:vertsize options:MTLResourceStorageModeShared]; + if (mtlbufvertex == nil) { + return SDL_OutOfMemory(); + } mtlbufvertex.label = @"SDL vertex data"; SDL_memcpy([mtlbufvertex contents], vertices, vertsize);