Git Product home page Git Product logo

Comments (3)

Zamiell avatar Zamiell commented on July 30, 2024

i dont remember exactly what the bugs are.
but your code snippet showcases why we don't recommend that people ever use it: typing local entity = roomEntities:Get(i) is a waste of time, and confusing for other people reading the code

from isaacdocs.

amaurymaille avatar amaurymaille commented on July 30, 2024

Isaac.GetRoomEntities() will return a table that is a view of the entities in the room at the time the function was called, while Room::GetEntities() will return a userdata that stores a raw pointer to the array in memory that stores the entities in the room. Therefore, iterating over the return value of Room::GetEntities() will always iterate over the entities present in the room during the current logic frame, while iterating over the return value of Isaac.GetRoomEntities() will iterate over the entities that were present at the time the function was called.

I'm not sure if the array in memory is sized in such a way that it can store the max possible amount of each entity to avoid resizes, but that's the risk when working with Room::GetEntities(): since the userdata has a copy of the pointer to the array of entities in memory, if this pointer gets invalidated, which may happen without changing rooms (because resizes), the game may crash when iterating over the content of the userdata. With Isaac.GetRoomEntities(), the game may crash only if you manipulate the entities inside after changing rooms (maybe also if the entity has been removed since, but I don't know when the game actually frees the memory associated with an entity, maybe it is safe).

from isaacdocs.

wofsauge avatar wofsauge commented on July 30, 2024

Ive improved the descriptions of both functions based on @amaurymaille `s post. Thank you very much for that cool explaination!

if anything other needs to be changed, please reopen the issue :)

Related commit: a877eb7

from isaacdocs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.