Sprite or animation definitions won't allow empty layers table as of 0.18.20

Place to post guides, observations, things related to modding that are not mods themselves.
posila
Factorio Staff
Factorio Staff
Posts: 5341
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Sprite or animation definitions won't allow empty layers table as of 0.18.20

Post by posila »

It is currently possible to define sprite or animation with layers set to empty table. This effectivelly makes animation to not load, while circumventing checks that mandatory animations are defined. This causes the game to crash when it tries to draw such animation or sprite.

From 0.18.19, sprite and animation definitions with empty layers will add warning (prefixed with "DATA WARNING" so you can search for it) to logs.

From 0.18.20, the game will fail to load with an error, even if for optional sprites. If sprite/animation is optional, just set it to nil, don't make it a table of empty layers.

Code: Select all

-- this won't be allowed
optional_picture = { layers = {} } 

-- instead of that do
optional_picture = nil
For mandatory definitions, you can use empty.png from core game.

Code: Select all

picture = { filename = "__core__/graphics/empty.png", size = 1 }
Pi-C
Smart Inserter
Smart Inserter
Posts: 1725
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Sprite or animation definitions won't allow empty layers table as of 0.18.20

Post by Pi-C »

I wanted to check for such empty layers in my mods and started Factorio with just these mods and their hard dependencies, but I didn't see any warning. So I deliberately made some empty layers in Bio Industries:

Code: Select all

function turret_pic(inputs)
return
{
        layers =
        {
		-- real definitions removed for testing
        }
}
end


data:extend({
  {
    type = "ammo-turret",
    name = "bi-dart-turret",
    icon = ICONPATH .. "bio_turret_icon.png",
    icon_size = 32,
    icons = {
      {
        icon = ICONPATH .. "bio_turret_icon.png",
        icon_size = 32,
      }
    },
    flags = {"placeable-player", "player-creation"},
    minable = {mining_time = 0.25, result = "bi-dart-turret"},
    max_health = 300,
    corpse = "medium-remnants",
    collision_box = {{-0.2, -0.2 }, {0.2, 0.2}},
    selection_box = {{-0.4, -0.4 }, {0.4, 0.4}},
    rotation_speed = 0.05,
    preparing_speed = 0.08,
    folding_speed = 0.08,
    dying_explosion = "medium-explosion",
    inventory_size = 1,
    automated_ammo_count = 14,
    attacking_speed = 1, -- makes nothing, it's animation's parameter

    folded_animation = turret_pic{direction_count = 8, line_length = 1},
    preparing_animation = turret_pic{direction_count = 8, line_length = 1},
    prepared_animation = turret_pic{},
    attacking_animation = turret_pic{},
    folding_animation = turret_pic{direction_count = 8, line_length = 1, run_mode = "backward"},

	[…]
  }
})
I expected to get a warning in the log file while data.lua was processed. However, the log file contains nothing of relevance:

Code: Select all

$ grep -i warning ../../factorio-current.log 
   8.432 Warning! Sprite at {0,0; 32x32} from __Natural_Evolution_Buildings__/graphics/icons/combat_inserter.png is defined with 4 mipmap levels, but level 1 is expected to be at {32,0; 16x16} which is out of bounds of the source image.
   8.511 Warning! Sprite at {0,0; 32x32} from __Natural_Evolution_Enemies__/graphics/icons/ne-spitter-land-mine.png is defined with 4 mipmap levels, but level 1 is expected to be at {32,0; 16x16} which is out of bounds of the source image.
Why don't I get a warning?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
posila
Factorio Staff
Factorio Staff
Posts: 5341
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Sprite or animation definitions won't allow empty layers table as of 0.18.20

Post by posila »

Pi-C wrote: Mon Apr 20, 2020 2:05 pm Why don't I get a warning?
No idea.
I tried the same thing in base (type doesn't matter) and got the warnings

Code: Select all

   2.536 DATA WARNING: Empty sprite layers in "ROOT.fluid-turret.flamethrower-turret.folded_animation.layers"
   2.536 DATA WARNING: Empty sprite layers in "ROOT.fluid-turret.flamethrower-turret.preparing_animation.layers"
   2.539 DATA WARNING: Empty sprite layers in "ROOT.fluid-turret.flamethrower-turret.folding_animation.layers"
Pi-C
Smart Inserter
Smart Inserter
Posts: 1725
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Sprite or animation definitions won't allow empty layers table as of 0.18.20

Post by Pi-C »

posila wrote: Mon Apr 20, 2020 6:55 pm
Pi-C wrote: Mon Apr 20, 2020 2:05 pm Why don't I get a warning?
No idea.
I tried the same thing in base (type doesn't matter) and got the warnings
Got them now too, after removing all mods but Bio Industries. I already had all it's files open and it seemed very convenient to just comment the layer definitions right there. Well, I should have picked another entity for testing -- one that isn't duplicated in Natural Evolution! So, BI defined the entity with the wrong layers (confirmed by logging the prototype data at the end of data.lua), then NE overwrote that with the proper layer definitions, and when the game checked the data, of course everything was alright. :oops:

At least I know now that the game really will complain on such errors, and that I should check related mods one after the other, not together. Sorry for the noise!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Post Reply

Return to “Modding discussion”