Icons generated at runtime do not have an assigned width or height unless forced by both adding that icon to the rsc and Scale() after loading it again. Attempting to scale an icon without a size before adding to the rsc does not work and will always result in 0 for both width and height.
Numbered Steps to Reproduce Problem:
1. Generate an icon from scratch
2. Attempt to rescale it to 32 x 32
3. Read the width and height
Code Snippet (if applicable) to Reproduce Problem:
/mob/verb/show_sizes()
var/icon/holder = new
world << "Blank slate icon: [holder.Width()]x[holder.Height()]"
holder.Scale(32, 32)
world << "Blank slate scaled: [holder.Width()]x[holder.Height()]"
// You can use any normal 32x32 sprite in a file for the line below
var/icon/added = new('icons/vis_testing.dmi', "white_fill", SOUTH)
world << "Loaded icon: [added.Width()]x[added.Height()]"
added.Blend(rgb(255, 0, 0))
world << "Blended icon: [added.Width()]x[added.Height()]"
holder.Insert(added, "something", SOUTH)
world << "Icon after insert: [holder.Width()]x[holder.Height()]"
holder.Scale(32, 32)
world << "Icon after insert + rescale: [holder.Width()]x[holder.Height()]"
var/cache = fcopy_rsc(holder)
holder = icon(cache)
world << "Icon after rsc: [holder.Width()]x[holder.Height()]"
holder.Scale(32, 32)
world << "Icon after rsc + rescale: [holder.Width()]x[holder.Height()]"
var/icon/reloaded = icon(holder, "something", SOUTH)
world << "Icon loaded from generated sheet: [reloaded.Width()]x[reloaded.Height()]"
reloaded.Scale(32, 32)
world << "Icon loaded from generated sheet and rescaled: [reloaded.Width()]x[reloaded.Height()]"
Output:
Blank slate icon: 0x0
Blank slate scaled: 0x0
Loaded icon: 32x32
Blended icon: 32x32
Icon after insert: 0x0
Icon after insert + rescale: 0x0
Icon after rsc: 0x0
Icon after rsc + rescale: 32x32
Icon loaded from generated sheet: 32x32
Icon loaded from generated sheet and rescaled: 32x32
Expected Results:
An icon with dimensions of 32 x 32
Actual Results:
An icon with dimensions of 0 x 0
Does the problem occur:
Every time? Or how often? Every time
In other games? Duplicated both in ss13 and a blank project
In other user accounts? Another coder got the same issue on beta 514
On other computers? Ditto above
When does the problem NOT occur?
After adding the generated icon to the rsc you become able to resize the icon normally to give it a proper size