Mtasa-blue: Fix infinite loop if a track runs across/crosses another

Created on 30 Dec 2018  路  3Comments  路  Source: multitheftauto/mtasa-blue

Call stack

image

bug

All 3 comments

This is caused by calls to something along the line of CTrain__findclosesttracknode in the game (I don't have my IDB's anymore it's a function in the game train class) basically what it does is goes looking for the closest track node but it never takes into account

  • track id
  • overlapping tracks

anything within a radius (I believe from memory 0.1f) would trigger this issue. This is so large because track position is stored as a short somewhere and divided down to a float so we lose precision and therefore it doesn't matter where it is.

my suggestion and what I was doing when I left was modifying this function to only scan the current track (we know it, why waste time?) and implement our own find closest track function taking care to be "safe" about loops.

The callstack above will probably contain the CTrain update method (the one called every frame), that will call the function that calculates position on the track which is likely where it stuck in a loop.

Basically the loop goes around to see if it found a new closest track node it'l keep going around but if it finds two then it gets stuck as it can't decide between the two (again due to loss of precision of the position x,y and z).

Edit: the function was either find closest track or find position on track

(I don't have my IDB's anymore

You can download latest GTA SA IDB from here:
https://mirror.mtasa.com/dev/gta_sa1.0us-IDBs.zip

I talked to @qaisjp about this. Here's the reversed code for CTrain::ProcessControl:
https://github.com/saml1er/gta-reversed/blob/master/source/game_sa/Entity/Vehicle/CTrain.cpp#L226

The reversed code is compilable . If we hook the original function, it should work. It's better to port the reversed code to MTA. We can create a new file for it (CTrainSA.h/.cpp) and replace it with CTrain::ProcessControl hook in MTA code:
https://github.com/multitheftauto/mtasa-blue/blob/master/Client/multiplayer_sa/CMultiplayerSA_CrashFixHacks.cpp#L1568

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PlatinMTA picture PlatinMTA  路  3Comments

qaisjp picture qaisjp  路  3Comments

Haxardous picture Haxardous  路  3Comments

christophercampbell1 picture christophercampbell1  路  4Comments

rk-r picture rk-r  路  4Comments