[0.12.6] Bushes & ghosts — LuaEntity API call … invalid

Bugs that are actually features.
Post Reply
erisco
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sun Aug 16, 2015 1:13 am
Contact:

[0.12.6] Bushes & ghosts — LuaEntity API call … invalid

Post by erisco »

Reproduction
1) Install QuickPrints mod v0.1.3 https://github.com/erisco/quickprints/releases.
2) Start a new game.
3) Place a ghost object on a bush (you can use QuickPrints to unlock the necessary tech for this).
4) Click on the "QuickPrints" button at the top and in the expanded GUI click "On".
5) Walk near the ghost object (the intent here is to have QuickPrints place the object, so you need one in your inventory).

This is the exception you'll get:
LueEntity_API_call.png
LueEntity_API_call.png (242.02 KiB) Viewed 6254 times
Relevant line is 232 https://github.com/erisco/quickprints/b ... l.lua#L232

Code: Select all

    local nearbyEntities = game.get_surface(1)
      .find_entities{minCorner, maxCorner}
    for _, entity in pairs(nearbyEntities) do 
      if entity and entity.name == "entity-ghost" then     -- line 232
      -- snip
      end
    end
You can see that I added a check that "entity" is truthy. I was not sure what was causing the exception at first and since it was rare I just threw that in (isn't any help). The exception is thrown when "entity.name" is read.

This is looping over all nearby entities, and somehow it is picking up something the game engine is not happy with, and for some reason bushes are relevant.

Starting on line 110 I create the entity to replace the ghost entity. https://github.com/erisco/quickprints/b ... l.lua#L110

Code: Select all

  local surface = game.get_surface(1)
  if surface.can_place_entity(properties) then
    surface.create_entity(properties)
    return true
  else
    return false
  end

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

Re: [0.12.6] Bushes & ghosts — LuaEntity API call … invalid

Post by Rseding91 »

Creating the entity destroys the bush the ghost is on thus invalidating the bush entity. This is normal and running as expected - not a bug.

Check for entity.valid before trying to read the name off the entity.
If you want to get ahold of me I'm almost always on Discord.

erisco
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sun Aug 16, 2015 1:13 am
Contact:

Re: [0.12.6] Bushes & ghosts — LuaEntity API call … invalid

Post by erisco »

Thanks, this resolved the issue.

Should be documented on https://forums.factorio.com/wiki/inde ... Lua/Entity else I don't see how anyone would know about this.

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

Re: [0.12.6] Bushes & ghosts — LuaEntity API call … invalid

Post by Rseding91 »

erisco wrote:Thanks, this resolved the issue.

Should be documented on https://forums.factorio.com/wiki/inde ... Lua/Entity else I don't see how anyone would know about this.
https://forums.factorio.com/wiki/inde ... d_property
If you want to get ahold of me I'm almost always on Discord.

erisco
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sun Aug 16, 2015 1:13 am
Contact:

Re: [0.12.6] Bushes & ghosts — LuaEntity API call … invalid

Post by erisco »

Okay cool. When should you check if an object has become invalid? Also, if there was a list of exceptions and probable causes that'd seem like a great place to mention this.

Post Reply

Return to “Not a bug”