diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:11:17 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:11:17 -0500 |
| commit | b6a73d3a89c52c1e3b06dfa930665e10379d9893 (patch) | |
| tree | 28833f773ea42486cb9edcb1fe52168a7a578947 /runtime/test/gameinput_test.cpp | |
| parent | 43f41a1d8d37b5e73d7d08d1925c2dc4bf547b90 (diff) | |
| parent | c5c9ff002ac564a687a3f3f4a418079e9881c8e0 (diff) | |
Merge pull request #4102 from Felix Croasdale
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 | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index 601a17c3e..eeb5de232 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -13,12 +13,14 @@ | |||
| 13 | #include <SDL3/SDL.h> | 13 | #include <SDL3/SDL.h> |
| 14 | 14 | ||
| 15 | #include <algorithm> | 15 | #include <algorithm> |
| 16 | #include <atomic> | ||
| 16 | #include <cmath> | 17 | #include <cmath> |
| 17 | #include <cstdint> | 18 | #include <cstdint> |
| 18 | #include <cstdio> | 19 | #include <cstdio> |
| 19 | #include <cstring> | 20 | #include <cstring> |
| 20 | #include <deque> | 21 | #include <deque> |
| 21 | #include <string> | 22 | #include <string> |
| 23 | #include <thread> | ||
| 22 | #include <vector> | 24 | #include <vector> |
| 23 | 25 | ||
| 24 | #include "gameinput.h" | 26 | #include "gameinput.h" |
| @@ -346,6 +348,14 @@ std::vector<uint8_t> raw_bytes(IGameInputRawDeviceReport* r) { | |||
| 346 | return v; | 348 | return v; |
| 347 | } | 349 | } |
| 348 | 350 | ||
| 351 | // RT-262: the poll thread takes a reference on a force-feedback effect only while it is alive. | ||
| 352 | void test_add_ref_if_live() { | ||
| 353 | std::atomic<unsigned long> live{1}, dying{0}; | ||
| 354 | check(rt::gameinput::add_ref_if_live(live) && live.load() == 2, "add_ref_if_live: a live count goes up by one"); | ||
| 355 | check(!rt::gameinput::add_ref_if_live(dying) && dying.load() == 0, | ||
| 356 | "add_ref_if_live: a count of 0 stays 0, so an effect being destroyed isn't revived"); | ||
| 357 | } | ||
| 358 | |||
| 349 | void test_raw_hid(IGameInput* input) { | 359 | void test_raw_hid(IGameInput* input) { |
| 350 | test_parse_report_descriptor(); | 360 | test_parse_report_descriptor(); |
| 351 | rt::gameinput::set_hid_backend(&kFakeRawHid); | 361 | rt::gameinput::set_hid_backend(&kFakeRawHid); |
| @@ -1384,6 +1394,28 @@ void test_force_feedback(IGameInput* input) { | |||
| 1384 | rt::gameinput::poll(); | 1394 | rt::gameinput::poll(); |
| 1385 | check(g_fake.destroys == 1, "force feedback: its SDL effect is destroyed on the poll thread"); | 1395 | check(g_fake.destroys == 1, "force feedback: its SDL effect is destroyed on the poll thread"); |
| 1386 | 1396 | ||
| 1397 | // RT-262: the title releases effects while the poll thread applies them. The poll thread used to AddRef an effect | ||
| 1398 | // whose count had already reached 0 (its destructor waiting for the lock), use it after it was freed, and free it | ||
| 1399 | // a second time with its own Release. | ||
| 1400 | { | ||
| 1401 | std::atomic<bool> stop{false}; | ||
| 1402 | std::thread poller([&] { | ||
| 1403 | while (!stop.load()) rt::gameinput::poll(); | ||
| 1404 | }); | ||
| 1405 | int created = 0; | ||
| 1406 | for (int i = 0; i < 20000; ++i) { | ||
| 1407 | IGameInputForceFeedbackEffect* e = nullptr; | ||
| 1408 | if (dev->CreateForceFeedbackEffect(0, ¶ms, reinterpret_cast<void**>(&e)) == S_OK && e) { | ||
| 1409 | ++created; | ||
| 1410 | e->Release(); | ||
| 1411 | } | ||
| 1412 | } | ||
| 1413 | stop = true; | ||
| 1414 | poller.join(); | ||
| 1415 | rt::gameinput::poll(); | ||
| 1416 | check(created == 20000, "force feedback: 20,000 effects created and released while the poll thread runs"); | ||
| 1417 | } | ||
| 1418 | |||
| 1387 | detach(wheel); | 1419 | detach(wheel); |
| 1388 | rt::gameinput::poll(); | 1420 | rt::gameinput::poll(); |
| 1389 | check(g_fake.closes == 1 && !dev->IsForceFeedbackMotorPoweredOn(0), | 1421 | check(g_fake.closes == 1 && !dev->IsForceFeedbackMotorPoweredOn(0), |
| @@ -1494,6 +1526,7 @@ int main() { | |||
| 1494 | set_env("LEONIDA_DS_TRIGGERS", nullptr); | 1526 | set_env("LEONIDA_DS_TRIGGERS", nullptr); |
| 1495 | set_env("LEONIDA_DS_LIGHTBAR", nullptr); | 1527 | set_env("LEONIDA_DS_LIGHTBAR", nullptr); |
| 1496 | set_env("LEONIDA_RUMBLE", nullptr); | 1528 | set_env("LEONIDA_RUMBLE", nullptr); |
| 1529 | test_add_ref_if_live(); | ||
| 1497 | 1530 | ||
| 1498 | auto create = reinterpret_cast<GameInputCreateFn>(rt::shims::find("gameinput.dll", "GameInputCreate")); | 1531 | auto create = reinterpret_cast<GameInputCreateFn>(rt::shims::find("gameinput.dll", "GameInputCreate")); |
| 1499 | check(create != nullptr, "gameinput.dll!GameInputCreate is registered"); | 1532 | check(create != nullptr, "gameinput.dll!GameInputCreate is registered"); |