18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 21:45:16 +01:00

Speed table: report a signal index that points past the end of the table (#489)

* fix(ai): report a signal index past the end of the speed table

TableTraceRoute() drops SemNextIndex / SemNextStopIndex when they point
past the end of the speed table. This used to catch the indices
TablePurger() and TableCheck() left behind; #178 fixed both, and nothing
else shrinks the table without resetting them, so the check should never
fire. It stays as a safety net, but now writes to errors.txt when it does
fire (vehicle, index, table size, last track and its distance, scan
range), so a new way of getting there is noticed instead of being hidden.

Not seen in the scenario suite (37 cases) nor in two runs of the whole
L053 poranek scenery with every train driven by AI (about 75 min of
simulation each).

* fix(ai): the stale index report captures what it uses and is built with std::format
This commit is contained in:
jerrrrycho
2026-11-25 05:23:53 +01:00
committed by GitHub
parent 0c01d660f6
commit 236a25eacb

View File

@@ -575,15 +575,21 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
}
else {
if( iTableDirection == 0 ) { return; }
// NOTE: belt and braces; TablePurger() used to leave these pointing past the end of the table
if( SemNextIndex != npos
&& SemNextIndex >= sSpeedTable.size() ) {
SemNextIndex = npos;
}
if( SemNextStopIndex != npos
&& SemNextStopIndex >= sSpeedTable.size() ) {
SemNextStopIndex = npos;
}
// NOTE: belt and braces; TablePurger() used to leave these pointing past the end of the table.
// nothing is known to do that any more, so say so when it happens
auto const dropstaleindex = [this, fDistance]( std::size_t &Index, std::string_view const Name ) {
if( Index == npos
|| Index < sSpeedTable.size() ) {
return;
}
ErrorLog( std::format(
"Speed table for {}: {} {} points past the end of the table ({} records), last track {} at {:.1f} m, scan range {:.1f} m; reset",
OwnerName(), Name, Index, sSpeedTable.size(),
( iLast >= 0 && sSpeedTable[ iLast ].trTrack != nullptr ? sSpeedTable[ iLast ].trTrack->name() : "none" ),
( iLast >= 0 ? sSpeedTable[ iLast ].fDist : 0.0 ), fDistance ) );
Index = npos; };
dropstaleindex( SemNextIndex, "SemNextIndex" );
dropstaleindex( SemNextStopIndex, "SemNextStopIndex" );
// kontynuacja skanowania od ostatnio sprawdzonego toru (w ostatniej pozycji zawsze jest tor)
if( SemNextStopIndex != npos
&& sSpeedTable[SemNextStopIndex].fVelNext == 0.0 ) {