Page 1 of 1

[boskid][2.0.23] Entity prototypes are missing "layers" information, leading to collision_mask_util.masks_collide crash

Posted: Sat Nov 30, 2024 1:12 am
by hgschmie
I have a prototype definition for an entity that contains a collision mask. The collision mask has an empty "layers" definition:
Screenshot 2024-11-29 at 17.00.07.png
Screenshot 2024-11-29 at 17.00.07.png (184.37 KiB) Viewed 423 times
Note that the prototype does define layers as empty (it can not be omitted; more about that in a second).

Now when I create an entity using LuaSurface::create_entity, this is what I receive:
Screenshot 2024-11-29 at 17.08.18.png
Screenshot 2024-11-29 at 17.08.18.png (316.97 KiB) Viewed 423 times


The prototype for this entity does NOT contain the layer information. I want to use collision_mask_util.masks_collide from the lualib to check whether any of these entities collides with others and that crashes my mod because the function assumes that any collision mask *does* contain a "layers" attribute.

Either any entity created by the game should contain the layers attribute even if it is empty (do not omit when there is no layer defined) *OR* the lualib needs to be tolerant of the layers attribute missing. The current state seems to be a bug.

Re: [boskid][2.0.23] Entity prototypes are missing "layers" information, leading to collision_mask_util.masks_collide cr

Posted: Sat Nov 30, 2024 3:33 pm
by boskid
Thanks for the report. Issue is now fixed for 2.0.24. My intention was to have "layers" be mandatory in all cases using the "make modders happy by reducing amount of formats data can be given" and this code was also structured in a way that was supposed to guarantee layers is given, however there is an intermediate step here when giving collision mask: it is first saved as one of the internal types, a PropertyTree where a "layers" was constructed however because it was not given any items it was considered as "unknown type" and as such it was not causing table to be pushed. I forced the type of this inner variable to explicitly say it is a table even if there are no items inside of it which fixes the issue.