Vice City: Multiplayer

Community Projects => SLC's Squirrel Plugin => Bug Reports => Topic started by: EK.IceFlake on May 25th, 2017, 11:06 AM

Title: [Fixed] Getting an unoccupied slot in a vehicle using .Occupant causes a crash
Post by: EK.IceFlake on May 25th, 2017, 11:06 AM
The title is enough: Getting an unoccupied slot in a vehicle using .Occupant causes a crash
Title: Re: [Bug] Getting an unoccupied slot in a vehicle using .Occupant causes a crash
Post by: . on May 25th, 2017, 03:35 PM
Ah yes, that was clearly a sh!tty choice https://github.com/iSLC/VCMP-SqMod/blob/41e04e5167efd765e25af6e52073f545932bec95/source/Entity/Vehicle.cpp#L262

Not checking whether the returned value is negative or out of bounds. Gonna fix it as soon as I can.
Title: Re: [Bug] Getting an unoccupied slot in a vehicle using .Occupant causes a crash
Post by: . on May 25th, 2017, 07:49 PM
In the mean time, if this is critical, you can validate the ID manually before using the actual thing:

Code: [Select]
if (vehicle.OccupantID(slot) >= 0)
{
    vehicle.Occupant(slot).stuff...
}

If you need this to be even stricter:

Code: [Select]
local oid = vehicle.OccupantID(slot);

if (oid >= 0 && oid < SqPlayer.MaxID)
{
    vehicle.Occupant(slot).stuff...
}
Title: Re: [Bug] Getting an unoccupied slot in a vehicle using .Occupant causes a crash
Post by: . on May 25th, 2017, 11:16 PM
Should be fixed now.