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

Avoid rare random crashes with game API #50

Closed
Vacuum-Tube opened this issue Mar 5, 2021 · 1 comment
Closed

Avoid rare random crashes with game API #50

Vacuum-Tube opened this issue Mar 5, 2021 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@Vacuum-Tube
Copy link

if vehicles and vehicles[1] and api.engine.getComponent(vehicles[1], api.type.ComponentType.TRANSPORT_VEHICLE).carrier then

You should be really careful with those direct indexing of getComponent.
I did this in my mod, too (very often) and got randomly "Error occured".

I got this info from UG:

There seems to be problems with temporaries, i.e. somehow "fatInstances" contains garbage, even if it is in the local scope. I still have to pin-point the problem exactly.
It seems that the library we are using to interface with C++ (sol2) is not liking the following:

​local fatInstances = api.engine.getComponent(id, api.type.ComponentType.MODEL_INSTANCE_LIST).fatInstances

If you change that to:

local comp = api.engine.getComponent(id, api.type.ComponentType.MODEL_INSTANCE_LIST)
local fatInstances = comp.fatInstances

the problem should be fixed.

I think this is a general issue with the library, where the lifetime of certain objects is incorrect, so (as a workaround) I suggest you try (as much as possible) to assign the result of "api" calls to temporary variables.

(This is mostly because the result of "api" calls are not lua tables, but is just lua userdata to real game objects or wrappers around them (in order to avoid expensive copies).)

@IncredibleHannes
Copy link
Owner

see #72 for fix

IncredibleHannes added a commit that referenced this issue Mar 16, 2021
removed direct indexing of getComponent as suggested in #50
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
Development

No branches or pull requests

2 participants