fix: don't crash if refreshrate decreases

fixes #76
This commit is contained in:
Virt 2025-05-08 20:28:38 +02:00
commit 1aabd346eb
3 changed files with 3 additions and 0 deletions

View file

@ -17,6 +17,7 @@ SModeResult CModeStretch::update(Vector2D pos) {
// create samples array // create samples array
int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate / 10)); // 100ms worth of history, avoiding divide by 0 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.resize(max, pos);
samples_index = std::min(samples_index, max - 1);
// capture current sample // capture current sample
samples[samples_index] = pos; samples[samples_index] = pos;

View file

@ -17,6 +17,7 @@ SModeResult CModeTilt::update(Vector2D pos) {
// create samples array // create samples array
int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate / 10)); // 100ms worth of history, avoiding divide by 0 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.resize(max, pos);
samples_index = std::min(samples_index, max - 1);
// capture current sample // capture current sample
samples[samples_index] = pos; samples[samples_index] = pos;

View file

@ -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 int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate)); // 1s worth of history, avoiding divide by 0
samples.resize(max); samples.resize(max);
samples_distance.resize(max); samples_distance.resize(max);
samples_index = std::min(samples_index, max - 1);
int previous = samples_index == 0 ? max - 1 : samples_index - 1; int previous = samples_index == 0 ? max - 1 : samples_index - 1;
samples[samples_index] = Vector2D{pos}; samples[samples_index] = Vector2D{pos};