egl/drm: do not crash when swapping buffers without any rendering
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Tue, 14 Oct 2014 09:39:47 +0000 (10:39 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Mon, 27 Oct 2014 17:36:21 +0000 (10:36 -0700)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
src/egl/drivers/dri2/platform_drm.c

index ab71f4b242a7269c321818f887bd9d852f2f570d..753c60f1426194db222a737cbfad081fe27b6da4 100644 (file)
@@ -418,6 +418,14 @@ dri2_drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
          for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++)
             if (dri2_surf->color_buffers[i].age > 0)
                dri2_surf->color_buffers[i].age++;
+
+         /* Make sure we have a back buffer in case we're swapping without
+          * ever rendering. */
+         if (get_back_bo(dri2_surf) < 0) {
+            _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers");
+            return EGL_FALSE;
+         }
+
          dri2_surf->current = dri2_surf->back;
          dri2_surf->current->age = 1;
          dri2_surf->back = NULL;