From 59f64e9532e9d1f3fdcadcc0b7a32d1fbb750c0f Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Thu, 25 May 2017 22:15:32 +0300 Subject: [PATCH] Make the occupant retrieval more error proof. --- source/Entity/Vehicle.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/source/Entity/Vehicle.cpp b/source/Entity/Vehicle.cpp index 3991b388..3b7cd0c6 100644 --- a/source/Entity/Vehicle.cpp +++ b/source/Entity/Vehicle.cpp @@ -258,8 +258,28 @@ LightObj & CVehicle::GetOccupant(Int32 slot) const { // Validate the managed identifier Validate(); + // Attempt to retrieve the requested information + const int id = _Func->GetVehicleOccupant(m_ID, slot); + // Was there an issue with the given value? + if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL)) + { + const vcmpError err = _Func->GetLastError(); + // Identify the type of error + if (err == vcmpErrorArgumentOutOfBounds) + { + STHROWF("Out of range slot [%d]", slot); + } + else if (err == vcmpErrorNoSuchEntity) + { + STHROWF("Unoccupied slot [%d]", id); + } + else + { + STHROWF("Error while getting occupant at [%d] for [%s]", slot, m_Tag.c_str()); + } + } // Return the requested information - return Core::Get().GetPlayer(_Func->GetVehicleOccupant(m_ID, slot)).mObj; + return Core::Get().GetPlayer(id).mObj; } // ------------------------------------------------------------------------------------------------