video: fix error messages - do not overwrite error message set by SDL_InitFormat (SDL_AllocFormat) - set proper error message (Cocoa_Metal_CreateView) - protect against allocation failure (UIKit_Metal_CreateView) (cherry picked from commit cf0cb44df88a4293805fdc926880155d58a46bea)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c
index e4dc0cc..561512b 100644
--- a/src/video/SDL_pixels.c
+++ b/src/video/SDL_pixels.c
@@ -530,7 +530,6 @@ SDL_AllocFormat(Uint32 pixel_format)
if (SDL_InitFormat(format, pixel_format) < 0) {
SDL_AtomicUnlock(&formats_lock);
SDL_free(format);
- SDL_InvalidParamError("format");
return NULL;
}
@@ -671,6 +670,7 @@ SDL_AllocPalette(int ncolors)
(SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors));
if (!palette->colors) {
SDL_free(palette);
+ SDL_OutOfMemory();
return NULL;
}
palette->ncolors = ncolors;
diff --git a/src/video/cocoa/SDL_cocoametalview.m b/src/video/cocoa/SDL_cocoametalview.m
index 2898485..7c424ba 100644
--- a/src/video/cocoa/SDL_cocoametalview.m
+++ b/src/video/cocoa/SDL_cocoametalview.m
@@ -144,6 +144,7 @@ Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
highDPI:highDPI
windowID:windowID];
if (newview == nil) {
+ SDL_OutOfMemory();
return NULL;
}
diff --git a/src/video/uikit/SDL_uikitmetalview.m b/src/video/uikit/SDL_uikitmetalview.m
index 8bc3380..e2e7015 100644
--- a/src/video/uikit/SDL_uikitmetalview.m
+++ b/src/video/uikit/SDL_uikitmetalview.m
@@ -92,6 +92,11 @@ UIKit_Metal_CreateView(_THIS, SDL_Window * window)
metalview = [[SDL_uikitmetalview alloc] initWithFrame:data.uiwindow.bounds
scale:scale];
+ if (metalview == nil) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
[metalview setSDLWindow:window];
return (void*)CFBridgingRetain(metalview);