From 0808daeae4b844f51ccea6f5ea9c5122df7473d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Garci=CC=81a=20Hierro?= Date: Mon, 11 Jun 2018 12:26:37 +0100 Subject: [PATCH] Avoid over-releasing the displayport in cmsYieldDisplay() Since cmsScanKeys() can generate multiple key presses when repeating the same key, cmsYieldDisplay() was releasing the displayport even if it wasn't grabbed and causing the grab/release calls to become unbalanced. --- src/main/cms/cms.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/cms/cms.c b/src/main/cms/cms.c index 6615872143a..bc00a960ec1 100644 --- a/src/main/cms/cms.c +++ b/src/main/cms/cms.c @@ -775,8 +775,13 @@ long cmsMenuExit(displayPort_t *pDisplay, const void *ptr) void cmsYieldDisplay(displayPort_t *pPort, timeMs_t duration) { + // Check if we're already yielding, in that case just extend + // the yield time without releasing the display again, otherwise + // the yield/grab become unbalanced. + if (cmsYieldUntil == 0) { + displayRelease(pPort); + } cmsYieldUntil = millis() + duration; - displayRelease(pPort); } // Stick/key detection and key codes @@ -1209,6 +1214,8 @@ void cmsUpdate(uint32_t currentTimeUs) // Only scan keys and draw if we're not yielding if (cmsYieldUntil == 0) { + // XXX: Note that one call to cmsScanKeys() might generate multiple keypresses + // when repeating, that's why cmsYieldDisplay() has to check for multiple calls. rcDelayMs = cmsScanKeys(currentTimeMs, lastCalledMs, rcDelayMs); // Check again, the keypress might have produced a yield if (cmsYieldUntil == 0) {