-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
Fix #1840: crash on disconnect #1842
Conversation
// Force delete all objects in cache | ||
// https://github.com/multitheftauto/mtasa-blue/issues/1840 | ||
g_pClientGame->GetElementDeleter()->DoDeleteAll(); | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Closing this in favor of #1846. |
Fixes #1840