From 0874e4e461e3ade9e3bf1f537732c5f849a15b5e Mon Sep 17 00:00:00 2001 From: Anton Kindestam Date: Sat, 24 Feb 2018 21:34:32 +0100 Subject: vo_drm: Fix pageflip errors on VT switch crtc_setup gets called on VT reacquire as well as during normal setup. When called during VT reacquire p->front_buf might not be 0, so the maths was wrong, and could cause array OOB errors. Use mathematically correct (for negative numbers) modulo to always pick the farthest away buffer (should work even for larger values of BUF_COUNT). --- video/out/vo_drm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'video') diff --git a/video/out/vo_drm.c b/video/out/vo_drm.c index 2cf88ad862..b25f036256 100644 --- a/video/out/vo_drm.c +++ b/video/out/vo_drm.c @@ -41,6 +41,9 @@ #define USE_MASTER 0 #define BUF_COUNT 2 +// Modulo that works correctly for negative numbers +#define MOD(a,b) ((((a)%(b))+(b))%(b)) + struct framebuffer { uint32_t width; uint32_t height; @@ -181,7 +184,7 @@ static bool crtc_setup(struct vo *vo) return true; p->old_crtc = drmModeGetCrtc(p->kms->fd, p->kms->crtc_id); int ret = drmModeSetCrtc(p->kms->fd, p->kms->crtc_id, - p->bufs[p->front_buf + BUF_COUNT - 1].fb, + p->bufs[MOD(p->front_buf - 1, BUF_COUNT)].fb, 0, 0, &p->kms->connector->connector_id, 1, &p->kms->mode); p->active = true; @@ -356,7 +359,7 @@ static void flip_page(struct vo *vo) p->bufs[p->front_buf].fb, DRM_MODE_PAGE_FLIP_EVENT, p); if (ret) { - MP_WARN(vo, "Cannot flip page for connector\n"); + MP_WARN(vo, "Failed to queue page flip: %s\n", mp_strerror(errno)); } else { p->front_buf++; p->front_buf %= BUF_COUNT; -- cgit v1.2.3