Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed crash when deleting actor while holding backspace #2866

Merged
merged 1 commit into from
Mar 11, 2022

Conversation

tritonas00
Copy link
Collaborator

Fixes #2860

It happened only on EV_COMMON_REMOVE_CURRENT_TRUCK, removing from top menu bar works fine.

@tritonas00 tritonas00 requested a review from ohlidalp March 11, 2022 06:48
Copy link
Member

@ohlidalp ohlidalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I know why this helps...
The 'backspace mode' does check if the player actor was removed:

if (!App::GetGameContext()->GetPlayerActor())
{
m_advanced_vehicle_repair = false;
m_advanced_vehicle_repair_timer = 0.0f;
return;
}

But if that code runs while DELETE message is already queued, then it's bust - it will queue the MODIFY message with a pointer to vehicle which will already be DELETE-d at the time of processing.
Well, I'm going to approve this for now, but it must eventually be redone like this:

typedef std::shared_ptr<Actor> ActorPtr;

enum ActorState { DELETED, /*existing ones*/ }

ActorManager:
    std::vector<ActorPtr> m_actors;

on MODIFY:
    // check if not already DELETED

on DELETE:
    // remove from ActorManager and set state to DELETED

That would also solve a potential issue with scripting - those may hold pointers to actors as well.
Unfortunately AngelScript doesn't support binding shared_ptr<>, so function proxies which check DELETED and nullptr would have to be added.

@tritonas00 tritonas00 merged commit 0357b92 into RigsOfRods:master Mar 11, 2022
@tritonas00 tritonas00 deleted the actor-crash branch March 11, 2022 09:30
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RoR crashes when pressing Ctrl+Del while holding Backspace
2 participants