[1.0.0] rendering.draw_sprite()s attached to entities are not destroyed properly when entity is destroyed

This subforum contains all the issues which we already resolved.
Post Reply
wladekb
Inserter
Inserter
Posts: 32
Joined: Wed Feb 27, 2019 8:48 pm
Contact:

[1.0.0] rendering.draw_sprite()s attached to entities are not destroyed properly when entity is destroyed

Post by wladekb »

Renderings made by rendering.draw_sprite() when targeted at entity are not cleared properly when the entity is destroyed
even though the docs say:
Note: If an entity target of an object is destroyed or changes surface, then the object is also destroyed.
See https://lua-api.factorio.com/latest/LuaRendering.html

Steps to reproduce:

1. Start a new game and execute this command:

Code: Select all

/c for i = 0, 10000, 1 do 
  local e = game.player.surface.create_entity{name="small-lamp", position={10,10}} 
  local r = rendering.draw_sprite{target=e,sprite="item.iron-ore",surface=game.player.surface} 
  e.destroy() 
end
2. See the "Script render preparation" (in show-time-usage) raise after each execution of the above code
3. Execute the following command to confirm that renderings are the root cause:

Code: Select all

/c rendering.clear()

On the other hand if you destroy renderings manually using rendering.destroy(r) the "Script render preparation" doesn't raise.

Code: Select all

/c for i = 0, 10000, 1 do 
  local e = game.player.surface.create_entity{name="small-lamp", position={10,10}} 
  local r = rendering.draw_sprite{target=e,sprite="item.iron-ore",surface=game.player.surface} 
  rendering.destroy(r)
  e.destroy() 
end
Expectations:

Renderings attached to entities are properly destroyed when the entity is destroyed.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13242
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.0.0] rendering.draw_sprite()s attached to entities are not destroyed properly when entity is destroyed

Post by Rseding91 »

Duplicate of viewtopic.php?p=498230#p498230

TLDR: they are removed 1 per tick per mod when invalid and you asked the game to make 10,000 of them so it's going to be 2.7 minutes before they're all removed.
If you want to get ahold of me I'm almost always on Discord.

wladekb
Inserter
Inserter
Posts: 32
Joined: Wed Feb 27, 2019 8:48 pm
Contact:

Re: [1.0.0] rendering.draw_sprite()s attached to entities are not destroyed properly when entity is destroyed

Post by wladekb »

Tldr Please add the above tldr to the docs or increase the speed of removal to at least 1% per tick.

Otherwise it is an unnecessary trap for mod develipers that I already fell into when trying to contribute a performance improvement (sic!) to Space Exploration which would easily replace adding 100 (or more) short-lived entities per second with sprites rendered using LuaRendering and the lag consistently built over time. Example of 10000 sprites was to clearly indicate the problem. The improvement is still valid after keeping the list of created sprites and removing them manually, but really... it would be much faster to have this implemented in c rather than in lua so please consider reworking the current logic.

Post Reply

Return to “Resolved Problems and Bugs”