From 1aabd346eb7ad12a614fd18d095d13422d8b95b4 Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Thu, 8 May 2025 20:28:38 +0200 Subject: [PATCH] fix: don't crash if refreshrate decreases fixes #76 --- src/mode/ModeStretch.cpp | 1 + src/mode/ModeTilt.cpp | 1 + src/other/Shake.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/mode/ModeStretch.cpp b/src/mode/ModeStretch.cpp index 576875d..9eb1203 100644 --- a/src/mode/ModeStretch.cpp +++ b/src/mode/ModeStretch.cpp @@ -17,6 +17,7 @@ SModeResult CModeStretch::update(Vector2D pos) { // create samples array int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate / 10)); // 100ms worth of history, avoiding divide by 0 samples.resize(max, pos); + samples_index = std::min(samples_index, max - 1); // capture current sample samples[samples_index] = pos; diff --git a/src/mode/ModeTilt.cpp b/src/mode/ModeTilt.cpp index c3e0b00..07cc2ba 100644 --- a/src/mode/ModeTilt.cpp +++ b/src/mode/ModeTilt.cpp @@ -17,6 +17,7 @@ SModeResult CModeTilt::update(Vector2D pos) { // create samples array int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate / 10)); // 100ms worth of history, avoiding divide by 0 samples.resize(max, pos); + samples_index = std::min(samples_index, max - 1); // capture current sample samples[samples_index] = pos; diff --git a/src/other/Shake.cpp b/src/other/Shake.cpp index 3530779..6adbddd 100644 --- a/src/other/Shake.cpp +++ b/src/other/Shake.cpp @@ -47,6 +47,7 @@ double CShake::update(Vector2D pos) { int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate)); // 1s worth of history, avoiding divide by 0 samples.resize(max); samples_distance.resize(max); + samples_index = std::min(samples_index, max - 1); int previous = samples_index == 0 ? max - 1 : samples_index - 1; samples[samples_index] = Vector2D{pos};