ID:2675025
 
BYOND Version:513
Operating System:Windows 10 Pro 64-bit
Web Browser:Firefox 88.0
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:
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

Can you package this into a test case with the icons you're using? (Not that I expect the icons much to matter, it's just good if we can be testing on the exact same stuff.)
I'm getting a virus warning when I try to download that zip. Very weird.

[edit]
Out of an abundance of caution I deleted the comment.
Looks like puush + zip is triggering that. I've taken out the build artifacts and moved the download to a different host and it doesn't seem to be triggering that.

https://www.dropbox.com/s/hsi5n4ggo4ajp05/ IconSizeTestcase.zip?dl=0
Ah, now that I see this I'm not sure this is a bug. The truth is icon/new() without a file has never been well defined and I don't think there is a correct behavior for it.
Even when an icon is added to it though it can't be resized and counts as 0x0 until it has been added to the rsc. I would expect it to take on the dimensions of the first icon inserted into it, or at the very least allow scaling to do that manually instead of requiring the seemingly unrelated operation of an fcopy_rsc.

As it is, the behavior is nonsensical and would have been near impossible to debug were I not by coincidence also adding the icon to the rsc manually. We have code that depends on being able to get the icon size for display in ui and this was breaking it before I figured it out.
It's always been like this. The icon() proc (which is the same as new/icon()) needs a file to begin with, even if the file is empty. There's no documentation of an icon() call with no arguments. You're starting with a broken icon and adding a working icon to it, when you should just be starting with the working icon.

I guess that makes this post more of a feature request.
It always being like this doesn't make it not a bug. Icons created without a file behave fine other than this.

If icons shouldn't be made without a file then the bug is in not throwing a runtime exception, if icons being made with a file is allowable then it makes no sense at all that it would change behavior from being added to the rsc.

There's a workaround that works fine here but the current behavior would be a massive pain in the ass to debug if I had not been lucky, and gives no indication as to what's wrong.