ID:2206472
 
(See the best response by Nadrew.)
Code:
        var/F = input("Please select an icon file.","Choose a *.dmi") as icon
var/icon/I = icon(F)

if(!usr.IsAdmin() && !usr.IsMaster() && !usr.IsIC())

if(length(I) > ico_size)
alert(usr,"Icon is [(length(I)/1024)]Kb! It must be [ico_size/1024]Kb or below.","Upload Icon")
return

if(I.Width() != 32 || I.Height() != 32)
alert(usr,{"Icon is "[I.Width()] x [I.Height()]". It must be 32 x 32!"},"Upload Icon")
return


Problem description:

I allow my players to use custom icons in the game once they have a certain number of points (SP) on their account. The point value increases the max file size allowed but players are only ever allowed to use 32x32 icons. My admins, myself, and players who contribute icons to the game are allowed to use larger icons though.

I have an occasional issue though and I'm not sure if maybe I'm just not using this right.

When players upload their custom icons, occasionally the I.Width() and I.Height() listed above will return a 0 for seemingly no reason even when the icon is absolutely 32x32.

Once it starts happening to a player, it will always happen to their custom icon no matter how many times they try to upload it but it wont prevent them from uploading a different icon. The only way for the player to use the icon again that was causing problems seems to be to open the icon file, edit it slightly like by changing a shade of blue slightly on 1 pixel. Then the game reads it as 32x32 again and will allow the icon.

It happens to me as well but because my account doesn't have the dimension restriction the icon just doesn't load and I become invisible.

This is a very intermittent issue and I haven't been able to pin it down. Is this a coding issue or is this possibly a byond bug?
Best response
This is usually a cache issue. Have the person trying to upload the icon close the game and clear their BYOND cache.
The upload doesn't change anything if it's redone because it'a already in the server cache.

I would guess this is a problem with timing on the server end, but it'd be a hard thing to pin down.
I've actually experienced issues with 'as icon' returning null on valid files if they're found in the cache, there should be a bug report buried about it somewhere.