LeoAdamek / iracing.rs

Rust library to connect to iRacing telemetry
MIT License
20 stars 4 forks source link

Missing Ticks #3

Open jnye opened 3 years ago

jnye commented 3 years ago

I tried using this library and I'm missing data ticks. I think the buffer from IRSDK is triple buffered and maybe this library is just looking at the first entry every time?

-- log from blocking sampler, notice gaps of 3 in ticks returned --- SessionTick = 30922 SessionTick = 30922 SessionTick = 30922 SessionTick = 30925 SessionTick = 30925 SessionTick = 30925 SessionTick = 30928 SessionTick = 30928 SessionTick = 30928

LeoAdamek commented 3 years ago

Sorry for the slow reply.

That is indeed quite odd.

Yes, iRacing has 4 buffers it uses for writing the telemetry data, currently only the first 3 are used. Each buffer contains the last tick on which it was updated.

This code is supposed to get the most recently updated buffer:

https://github.com/LeoAdamek/iracing.rs/blob/master/src/telemetry.rs#L338-L350

Seems perhaps this isn't working? I'll try and have a look when I get some time.

parasyte commented 3 years ago

This bug occurs because the Header is copied to Blocking: https://github.com/LeoAdamek/iracing.rs/blob/5977462bd55c0dfc7efd1d0b0fe7a12adb3fb5eb/src/telemetry.rs#L777-L779

Now that Blocking owns a clone of Header, it will simply reuse that clone every time it gets an event signaling an update. The code you linked that is looking for the latest buffer works, but it always uses an old clone of the header.

This is trivial to fix; just don't clone Header. Let Blocking create a new Header clone from shared memory on demand. With that, you can get the expected SessionTick values from each sample:

[Tick    143604] Lap   1: 2392.550s Gear 0 @   800 RPM GREEN_FLAG(4)
[Tick    143605] Lap   1: 2392.567s Gear 0 @   800 RPM GREEN_FLAG(4)
[Tick    143606] Lap   1: 2392.583s Gear 0 @   800 RPM GREEN_FLAG(4)
[Tick    143607] Lap   1: 2392.600s Gear 0 @   800 RPM GREEN_FLAG(4)
[Tick    143608] Lap   1: 2392.617s Gear 0 @   800 RPM GREEN_FLAG(4)
[Tick    143609] Lap   1: 2392.633s Gear 0 @   805 RPM GREEN_FLAG(4)
[Tick    143610] Lap   1: 2392.650s Gear 0 @   805 RPM GREEN_FLAG(4)
[Tick    143611] Lap   1: 2392.667s Gear 0 @   805 RPM GREEN_FLAG(4)
LeoAdamek commented 2 years ago

This should be getting fixed in the fixes to #8