Improve: Guard against divide by 0 in various cursor effects.

This commit is contained in:
Sewer56 2025-03-29 04:52:01 +00:00
commit 05c599b7d9
4 changed files with 6 additions and 4 deletions

View file

@ -33,7 +33,9 @@ void tickRaw(SP<CEventLoopTimer> self, void* data) {
if (isEnabled()) if (isEnabled())
g_pDynamicCursors->onTick(g_pPointerManager.get()); g_pDynamicCursors->onTick(g_pPointerManager.get());
const int TIMEOUT = g_pHyprRenderer->m_pMostHzMonitor ? 1000.0 / g_pHyprRenderer->m_pMostHzMonitor->refreshRate : 16; const int TIMEOUT = g_pHyprRenderer->m_pMostHzMonitor && g_pHyprRenderer->m_pMostHzMonitor->refreshRate > 0
? 1000.0 / g_pHyprRenderer->m_pMostHzMonitor->refreshRate
: 16;
self->updateTimeout(std::chrono::milliseconds(TIMEOUT)); self->updateTimeout(std::chrono::milliseconds(TIMEOUT));
} }

View file

@ -15,7 +15,7 @@ SModeResult CModeStretch::update(Vector2D pos) {
auto limit = g_pShapeRuleHandler->getIntOr(CONFIG_STRETCH_LIMIT, **PLIMIT); auto limit = g_pShapeRuleHandler->getIntOr(CONFIG_STRETCH_LIMIT, **PLIMIT);
// create samples array // create samples array
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history int max = std::max(1, (int)(g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10)); // 100ms worth of history, avoiding divide by 0
samples.resize(max, pos); samples.resize(max, pos);
// capture current sample // capture current sample

View file

@ -15,7 +15,7 @@ SModeResult CModeTilt::update(Vector2D pos) {
auto limit = g_pShapeRuleHandler->getIntOr(CONFIG_TILT_LIMIT, **PLIMIT); auto limit = g_pShapeRuleHandler->getIntOr(CONFIG_TILT_LIMIT, **PLIMIT);
// create samples array // create samples array
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history int max = std::max(1, (int)(g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10)); // 100ms worth of history, avoiding divide by 0
samples.resize(max, pos); samples.resize(max, pos);
// capture current sample // capture current sample

View file

@ -44,7 +44,7 @@ double CShake::update(Vector2D pos) {
static auto* const* PIPC = (Hyprlang::INT* const*) getConfig(CONFIG_SHAKE_IPC); static auto* const* PIPC = (Hyprlang::INT* const*) getConfig(CONFIG_SHAKE_IPC);
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate; // 1s worth of history int max = std::max(1, (int)(g_pHyprRenderer->m_pMostHzMonitor->refreshRate)); // 1s worth of history, avoiding divide by 0
samples.resize(max); samples.resize(max);
samples_distance.resize(max); samples_distance.resize(max);