Skip to content

Conversation

@abrahamtorrestorres
Copy link
Contributor

This fixes the crashes when disconnecting/stopping the resource and there's a ped/player element loaded.

The error happened because trying to set the element model of an already destroyed element causes a memory access violation error and crashed the game.

The ped/player elements were destroyed automatically by the engine when disconnecting, so this line is not necessary.

…dler

This fixes the crashes when disconnecting/stopping the resource and there's a ped/player element loaded.

The error happened because trying to set the element model of an already destroyed element causes a memory access violation error and crashed the game.

The ped/player elements were destroyed automatically by the engine when disconnecting, so this line is not necessary.
@abrahamtorrestorres abrahamtorrestorres changed the title Remove restoreElementBaseModels() from onClientResourceStop event han… Remove restoreElementBaseModels() from onClientResourceStop event handler Jul 27, 2025
@Fernando-A-Rocha
Copy link
Owner

@abrahamtorrestorres Why not check isElement to see if it got destroyed?

@abrahamtorrestorres
Copy link
Contributor Author

I've tried using

if isElement(element) then
    setElementModelMTA(element, loadedModel.baseModel)
end

But this still caused a crash.

The getElementModel function does not cause issues, only setElementModel does.

It seems the element is not destroyed yet when doing the verifications with isElement(element), but when using setElementModel, at the moment the operation begins, the model has been destroyed already, causing a memory access violation error.

@Fernando-A-Rocha
Copy link
Owner

@abrahamtorrestorres Ok I understand but you are removing restoreElementBaseModels() from onClientResourceStop
In case of a resource restart, did you test if this causes a bug where the custom model won't be applied on start?

@abrahamtorrestorres
Copy link
Contributor Author

After testing, when the resource is stopped, players get their model ID set to ID 0 (CJ model) and custom objects get turned back to their base model ID, and when starting it again, they get assigned their custom model back.

If there's something else that needs testing in order to be sure this doesn't cause issues, I'd be glad to assist.

@Fernando-A-Rocha
Copy link
Owner

Thank you. Seems valid

@Fernando-A-Rocha
Copy link
Owner

Will be featured in next update

@Fernando-A-Rocha Fernando-A-Rocha merged commit ea9b970 into Fernando-A-Rocha:main Jul 31, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants