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
ParticleSpawner (and maybe sound) IDs Reused #14044
Comments
For sound ids, there was this: #12780 (Not merged.) |
Note that not reusing IDs doesn't get rid of the race condition, it just makes the window so big that it practically doesn't matter. |
Also if the IDs are expired, even if some part of the Lua side is told, there's no way to effectively guarantee that everywhere the ID ended up in the Lua side is clear about the reuse. It's also somewhat unnecessary to require that the Lua side be responsible for dealing with this when it's easily dealt with centrally by either engine or builtin. If I attempt to delete a handle that's expired, even if I reasonably should have known that it did, there's no reason I need to be punished by having some other arbitrary resource deleted instead; it would be perfectly reasonable to just do nothing. |
FYI the workaround for this I have in NodeCore is: https://gitlab.com/sztest/nodecore/-/blob/dev/mods/nc_api/compat_issue14044.lua I am posting this because:
I am probably going to have to put this into a couple of other games too (even if the fix gets implemented and merged very soon, it will still be months before it's officially released, and many more before I can EOS the old release) so knowing the shape that an engine-side fix would take would help. If we were going to encapsulate resource IDs as e.g. userdata types, that would make it a lot simpler for me to detect the fixed version and bypass the workaround cache. |
The easiest method to "detect" the fixed version is when the bugfix also adds a field to the |
Minetest version
Active renderer
OpenGL 4.2
Irrlicht device
X11
Operating system and version
Debian 12
CPU model
Intel i5-3320M (4) @ 3.300GHz
GPU model
No response
OpenGL version
No response
Summary
Particle spawner IDs are aggressively reused, which can lead to deleting the wrong particle spawner.
It looks like the "ID" that MT returns for a particle spawner is not actually a unique identifier for that spawner, but an address (i.e. index of an array). So if I create particle spawner X and it gets assigned ID 3, then when I later call delete_particlespawner(3) I am not actually saying "delete particle spawner X", I'm unwittingly saying "delete whatever particle spawner currently occupies index 3". If X had already been deleted for some other reason (expiry, deletion by some other mod) then some other arbitrary particle spawner may now occupy that slot and be deleted instead.
The correct thing to do would be to use a unique value for each resource. A mapping of resource unique ID to address could be maintained in the engine.
Ideally the resource identifiers would be opaque to Lua (e.g. userdata) to prevent users from attempting to rely on the content/structure of the values, or to try to serialize and store them, or try to fabricate them.
Steps to reproduce
WARNING: Do NOT attempt to test this against NodeCore version
02673309-161dcfb0
or later, as there is already a workaround present that makes the bug unreproducible.Install this mod code into a worldmod:
Stand still while looking out into open air, and observe that now a cloud of black particles will revolve around the center of the player's view. This cloud is "smooth" and has no obvious gaps.
Now, add this code to a worldmod (it doesn't matter if it's in the same or different mod):
This will add a cloud of white particles that randomly teleports around the player.
Note that the black particle cloud "clock" will now have visible gaps in it, even though:
Note that the gaps may be subtle and difficult to differentiate against just the randomness of particle distribution in the cloud, but you an definitely see the difference in smoothness if you watch for a while and compare against the case without the teleporting white clouds. Some of the black cloud particlespawners are getting deleted too early.
The text was updated successfully, but these errors were encountered: