diff options
| author | Noname0202 <marta.indra2002@gmail.com> | 2026-11-23 19:26:21 +0100 |
|---|---|---|
| committer | Noname0202 <marta.indra2002@gmail.com> | 2026-11-23 19:26:21 +0100 |
| commit | 3bbf352b7a9f71ba6bd1c69f8774c4f320233cc4 (patch) | |
| tree | 87d311c968a67fdcd64731f3b40ce9aa1aaba3f5 /runtime/test/gameinput_test.cpp | |
| parent | 34702237c00e08f0b9e6af7a12aa979095938d25 (diff) | |
gameinput: SetHapticMotorState saturates a request's end time instead of wrapping
IGameInputDevice::SetHapticMotorState computed the end of a request as
duration * playCount + repeatDelay * (playCount - 1), then now + total, all
in uint64 microseconds with no overflow check. A very long request wrapped:
duration = UINT64_MAX with playCount 1 put the deadline just before now, so
the motor never played, and duration = 2^63 + 50 ms with playCount 2 wrapped
to a 100 ms request that stopped early.
The products and sums now saturate at UINT64_MAX, a deadline the poll
thread never reaches, so such a request plays until the state is set again.
Requests that fit are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
| -rw-r--r-- | runtime/test/gameinput_test.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index 7217dc37b..3e6b4b309 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -1599,6 +1599,27 @@ void test_haptic_motors(IGameInput* input) { | |||
| 1599 | rt::gameinput::poll(); | 1599 | rt::gameinput::poll(); |
| 1600 | check(xbox.left == 0, "haptics: releasing both leaves the trigger silent"); | 1600 | check(xbox.left == 0, "haptics: releasing both leaves the trigger silent"); |
| 1601 | 1601 | ||
| 1602 | // A request too long for a uint64 microsecond deadline plays until it is set again: the end time saturates | ||
| 1603 | // instead of wrapping into the past (never plays) or into the near future (stops early). | ||
| 1604 | p.intensity = 1.0f; | ||
| 1605 | p.playCount = 1; | ||
| 1606 | p.duration = UINT64_MAX; | ||
| 1607 | p.repeatDelay = 0; | ||
| 1608 | check(dev->SetHapticMotorState(0, &p) == S_OK, "haptics: a duration of UINT64_MAX is accepted"); | ||
| 1609 | rt::gameinput::poll(); | ||
| 1610 | check(xbox.left == 65535, "haptics: and plays (its end time does not wrap into the past)"); | ||
| 1611 | p.duration = (1ull << 63) + 50'000; // times 2 wraps to 100 ms | ||
| 1612 | p.playCount = 2; | ||
| 1613 | check(dev->SetHapticMotorState(1, &p) == S_OK, "haptics: duration * playCount past UINT64_MAX is accepted"); | ||
| 1614 | rt::gameinput::poll(); | ||
| 1615 | Sleep(130); | ||
| 1616 | rt::gameinput::poll(); | ||
| 1617 | check(xbox.right == 65535, "haptics: and keeps playing (the product does not wrap to a short request)"); | ||
| 1618 | dev->SetHapticMotorState(0, nullptr); | ||
| 1619 | dev->SetHapticMotorState(1, nullptr); | ||
| 1620 | rt::gameinput::poll(); | ||
| 1621 | check(xbox.left == 0 && xbox.right == 0, "haptics: both long requests stop when the state is cleared"); | ||
| 1622 | |||
| 1602 | detach(xbox); | 1623 | detach(xbox); |
| 1603 | rt::gameinput::poll(); | 1624 | rt::gameinput::poll(); |
| 1604 | check(rt::gameinput::connected_count() == 0, "haptics: detached"); | 1625 | check(rt::gameinput::connected_count() == 0, "haptics: detached"); |