YaGL: Fixed a crash in MacOS with Radeon HD
authorjinhyung.jo <jinhyung.jo@samsung.com>
Mon, 13 Jul 2015 11:19:28 +0000 (20:19 +0900)
committerjinhyung.jo <jinhyung.jo@samsung.com>
Tue, 14 Jul 2015 06:25:29 +0000 (15:25 +0900)
In OS X with Radeon HD,
CGLChoosePixelFormat fails to create the CGLPixelFormatObj
with the prefered_pixel_format_legacy_attrs.
But it does not return an error value.
There is a bug in the error handling in that case.
For that reason, yagl_egl_driver_create fails.

Change-Id: I2eb7b514287d1a5ec4801c76761841763f45594b
Signed-off-by: Jinhyung Jo <jinhyung.jo@samsung.com>
hw/yagl/yagl_drivers/egl_cgl/yagl_egl_cgl.c

index 75b0462..9b9422e 100644 (file)
@@ -59,6 +59,7 @@ static const CGLPixelFormatAttribute prefered_pixel_format_legacy_attrs[] =
     kCGLPFASampleBuffers, 1,
     kCGLPFASamples, 4,
     kCGLPFAPBuffer,
+    kCGLPFAOpenGLProfile, kCGLOGLPVersion_Legacy,
     0
 };
 
@@ -86,6 +87,7 @@ static const CGLPixelFormatAttribute pixel_format_legacy_attrs[] =
     kCGLPFADepthSize, 24,
     kCGLPFAStencilSize, 8,
     kCGLPFAPBuffer,
+    kCGLPFAOpenGLProfile, kCGLOGLPVersion_Legacy,
     0
 };
 
@@ -137,13 +139,17 @@ static CGLError yagl_egl_cgl_choose_pixel_format(const CGLPixelFormatAttribute p
 
     error = CGLChoosePixelFormat(prefered_attrs, pix, n);
 
-    if (error || !pix) {
-        YAGL_LOG_WARN("CGLChoosePixelFormat: no suitable prefered format found (%s)",
+    if (error) {
+        YAGL_LOG_WARN("CGLChoosePixelFormat: error occurs (%s)",
                       CGLErrorString(error));
         return CGLChoosePixelFormat(fallback_attrs, pix, n);
+    } else if (*pix == NULL || *n == 0) {
+        YAGL_LOG_WARN("CGLChoosePixelFormat: no suitable prefered format found");
+        return CGLChoosePixelFormat(fallback_attrs, pix, n);
+    } else {
+        return error;
     }
 
-    return error;
 }
 
 static bool yagl_egl_cgl_get_gl_version(struct yagl_egl_cgl *egl_cgl,