fix(Core/Vehicles): Fix crash in Vehicle::AddPassenger (#17038)

* fix(Crash): Fix crash in Vehicle::AddPassenger

As I understand it, a try-catch block cannot intercept the ABORT function. Therefore, let's use a simple if statement instead.

* Address code review feedback
This commit is contained in:
Anton Popovichenko
2023-08-22 12:13:36 +02:00
committed by GitHub
parent e42f43784c
commit 4c287e2873
+10 -13
View File
@@ -388,22 +388,19 @@ bool Vehicle::AddPassenger(Unit* unit, int8 seatId)
&& unit->GetTypeId() == TYPEID_PLAYER && unit->GetTypeId() == TYPEID_PLAYER
&& seat->second.SeatInfo->m_flags & VEHICLE_SEAT_FLAG_CAN_CONTROL) && seat->second.SeatInfo->m_flags & VEHICLE_SEAT_FLAG_CAN_CONTROL)
{ {
try // Removed try catch + ABORT() here, and make it as simple condition check.
if (!_me->SetCharmedBy(unit, CHARM_TYPE_VEHICLE))
{ {
if (!_me->SetCharmedBy(unit, CHARM_TYPE_VEHICLE)) // I assume SetCharmedBy should always be true.
ABORT(); // If not, let's log some debug info.
} LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). not null: {}", _me ? 1 : 0);
catch (...)
{
LOG_INFO("vehicles", "CRASH! Try-catch in Unit::SetCharmedBy()!");
LOG_INFO("vehicles", "CRASH! Try-catch in Unit::SetCharmedBy(). not null: {}", _me ? 1 : 0);
if (!_me) if (!_me)
return false; return false;
LOG_INFO("vehicles", "CRASH! Try-catch in Unit::SetCharmedBy(). Is: {}!", _me->IsInWorld()); LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). Is: {}!", _me->IsInWorld());
LOG_INFO("vehicles", "CRASH! Try-catch in Unit::SetCharmedBy(). Is2: {}!", _me->IsDuringRemoveFromWorld()); LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). Is2: {}!", _me->IsDuringRemoveFromWorld());
LOG_INFO("vehicles", "CRASH! Try-catch in Unit::SetCharmedBy(). Unit {}!", _me->GetName()); LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). Unit {}!", _me->GetName());
LOG_INFO("vehicles", "CRASH! Try-catch in Unit::SetCharmedBy(). typeid: {}!", _me->GetTypeId()); LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). typeid: {}!", _me->GetTypeId());
LOG_INFO("vehicles", "CRASH! Try-catch in Unit::SetCharmedBy(). Unit {}, typeid: {}, in world: {}, duringremove: {} has wrong CharmType! Charmer {}, typeid: {}, in world: {}, duringremove: {}.", _me->GetName(), _me->GetTypeId(), _me->IsInWorld(), _me->IsDuringRemoveFromWorld(), unit->GetName(), unit->GetTypeId(), unit->IsInWorld(), unit->IsDuringRemoveFromWorld()); LOG_INFO("vehicles", "Crash recovered in Unit::SetCharmedBy(). Unit {}, typeid: {}, in world: {}, duringremove: {} has wrong CharmType! Charmer {}, typeid: {}, in world: {}, duringremove: {}.", _me->GetName(), _me->GetTypeId(), _me->IsInWorld(), _me->IsDuringRemoveFromWorld(), unit->GetName(), unit->GetTypeId(), unit->IsInWorld(), unit->IsDuringRemoveFromWorld());
return false; return false;
} }
} }