Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix #1840: crash on disconnect #1842

Conversation

TheNormalnij
Copy link
Contributor

@TheNormalnij TheNormalnij commented Nov 16, 2020

Fixes #1840

@qaisjp qaisjp changed the title Fix: "Crash on disconnect #1840" Fix #1840: crash on disconnect Nov 16, 2020
Comment on lines +91 to +94
// Force delete all objects in cache
// https://github.com/multitheftauto/mtasa-blue/issues/1840
g_pClientGame->GetElementDeleter()->DoDeleteAll();

Copy link

Choose a reason for hiding this comment

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

The entire purpose of having the element deleter is to call CElementDeleter::DoDeleteAll in pulses from CClientGame::DoPulses. There should be a better way to fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then stopResource will crashes.
CClientGame::DoPulses contains m_ElementDeleter.DoDeleteAll(); at 1135

Copy link

@ghost ghost Nov 16, 2020

Choose a reason for hiding this comment

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

Then stopResource will crashes.

Nope, if you do it properly. This code will fix one crash but introduce more crashes since you are forcefully deleting the objects. There's a reason why the entity deletion is delayed, i.e., to avoid dangling pointers in gta code by delaying deletion.

I investigated this crash. The CBaseModelInfoInterface instance is deleted before the object is internally deleted. You can use std::shared_ptr<CClientModel> to solve this. In CClientObject::CClientObject, you can increment the shared_ptr reference count by simply holding a shared_ptr and decrement shared_ptr reference count in CClientObject::~CClientObject by setting the shared_ptr varaible to nullptr.

In this way, when all objects are deleted, then the reference count of CClientModel will reach zero and the destructor will be called automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

~CClientObject don't delete object from GTA:SA pool. So ~CClientObject hide obejct from CClientModel and CClientModel can't replace this model with safe ID. MTA try delete object from pool, but can't, because modelInfo is invalid

@StrixG StrixG added the bug Something isn't working label Nov 17, 2020
@ghost
Copy link

ghost commented Nov 17, 2020

Closing this in favor of #1846.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on disconnect
2 participants