fix(iracing): fix non-Latin driver names showing as ??? in session YAML#15
Conversation
…s set, use system ACP for fallback
There was a problem hiding this comment.
Code Review
This pull request adds support for UTF-8 session strings in iRacing telemetry and dynamically resolves the Windows system Active Code Page (ACP) instead of hardcoding CP-1252. Feedback suggests caching the resolved system ACP encoding using std::sync::OnceLock to avoid the overhead of calling the FFI function GetACP() on every string decoding operation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| fn system_acp_encoding() -> &'static encoding_rs::Encoding { | ||
| #[cfg(all(windows, any(feature = "iracing", feature = "ac-evo", feature = "lmu")))] | ||
| { | ||
| // SAFETY: GetACP() is always safe to call and never fails. | ||
| let acp = unsafe { windows_sys::Win32::Globalization::GetACP() }; | ||
| match acp { | ||
| 1251 => encoding_rs::WINDOWS_1251, | ||
| 1252 => encoding_rs::WINDOWS_1252, | ||
| 1250 => encoding_rs::WINDOWS_1250, | ||
| 1253 => encoding_rs::WINDOWS_1253, | ||
| 1254 => encoding_rs::WINDOWS_1254, | ||
| 1255 => encoding_rs::WINDOWS_1255, | ||
| 1256 => encoding_rs::WINDOWS_1256, | ||
| 1257 => encoding_rs::WINDOWS_1257, | ||
| 1258 => encoding_rs::WINDOWS_1258, | ||
| 874 => encoding_rs::WINDOWS_874, | ||
| 932 => encoding_rs::SHIFT_JIS, | ||
| 936 => encoding_rs::GBK, | ||
| 949 => encoding_rs::EUC_KR, | ||
| 950 => encoding_rs::BIG5, | ||
| _ => encoding_rs::WINDOWS_1252, | ||
| } | ||
| } | ||
| #[cfg(not(all(windows, any(feature = "iracing", feature = "ac-evo", feature = "lmu"))))] | ||
| { | ||
| encoding_rs::WINDOWS_1252 | ||
| } | ||
| } |
There was a problem hiding this comment.
Calling GetACP() on every string decoding operation can introduce unnecessary FFI overhead, especially since telemetry string decoding can happen multiple times per frame. Since the system active code page (ACP) does not change during the lifetime of the process, we can cache the resolved encoding using std::sync::OnceLock to completely eliminate this overhead after the first call.
fn system_acp_encoding() -> &'static encoding_rs::Encoding {
static ENCODING: std::sync::OnceLock<&'static encoding_rs::Encoding> = std::sync::OnceLock::new();
*ENCODING.get_or_init(|| {
#[cfg(all(windows, any(feature = "iracing", feature = "ac-evo", feature = "lmu")))]
{
// SAFETY: GetACP() is always safe to call and never fails.
let acp = unsafe { windows_sys::Win32::Globalization::GetACP() };
match acp {
1251 => encoding_rs::WINDOWS_1251,
1252 => encoding_rs::WINDOWS_1252,
1250 => encoding_rs::WINDOWS_1250,
1253 => encoding_rs::WINDOWS_1253,
1254 => encoding_rs::WINDOWS_1254,
1255 => encoding_rs::WINDOWS_1255,
1256 => encoding_rs::WINDOWS_1256,
1257 => encoding_rs::WINDOWS_1257,
1258 => encoding_rs::WINDOWS_1258,
874 => encoding_rs::WINDOWS_874,
932 => encoding_rs::SHIFT_JIS,
936 => encoding_rs::GBK,
949 => encoding_rs::EUC_KR,
950 => encoding_rs::BIG5,
_ => encoding_rs::WINDOWS_1252,
}
}
#[cfg(not(all(windows, any(feature = "iracing", feature = "ac-evo", feature = "lmu"))))]
{
encoding_rs::WINDOWS_1252
}
})
}
Problem
Driver names with Cyrillic (and other non-Latin) characters appeared as
?in the session YAML. Two root causes:
session_yaml()always decoded bytes as CP-1252, but iRacing now sendsthe session string as UTF-8 when
irsdkUTF8SessionStris set (introducedto support international names). UTF-8 bytes decoded as CP-1252 →
?.For the non-UTF-8 fallback path, CP-1252 was hardcoded. On Russian Windows
the system ACP is CP-1251, so Cyrillic bytes were still corrupted even
before iRacing added the UTF-8 flag.
Changes
session_yaml()now reads theirsdkUTF8SessionStrtelemetry variable atruntime and switches to
String::from_utf8_lossywhen it is non-zero.decode_cp1252now callsGetACP()(Win32) to pick the correct codec fromencoding_rsbased on the actual system locale instead of always usingCP-1252. Supports CP-1251/1250/1253/1254/1255/1256/1257/1258/874/932/936/949/950.
Win32_Globalizationfeature to thewindows-sysdependency.