ID:2477794
 
Code:
client/proc/DisplayTitleScreen()
var/icon/i = icon('TitleScreen.png')
var
w = i.Width()
h = i.Height()
if(!w || !h)
world.log << "ERROR: Width or Height of title screen bugged out!"
return
//more code to finish up title screen


Problem description:
Like 25% of the time this code will fail to get the width & height of a PNG image for no apparent reason using this same exact code with the same exact image (TitleScreen.png) but it happens with any png. I think this is a BYOND bug but is there something I can do to this code to more reliably get the width & height of this PNG? Thanks.

The other 75% of the time it fetches the width & height just fine and displays the title screen. There is no apparent reason.
Has anyone experienced this? Just me? Hmm I guess I'll just import the PNGs into a very big DMI file instead so that Width()/Height() don't fail on it anymore.
DMI files are just PNG files with a special header and with a little bit of extra metadata stored in the zTXT block of the file.
Yeah but all the same using Width()/Height() on a PNG in this example is often failing for some reason.
Now it just threw an error in game. It pops up in one of those windows error dialogs that looks like this https://docs.microsoft.com/en-us/windows/desktop/uxguide/ images/mess-error-image15.png

except it says "Premature end of JPEG" (even though its not a JPEG but a PNG im using)
Are you displaying the image in a browser output or trying to display it as an object on the map?
In response to Maximus_Alex2003
I am adding the image to client.images. So I suppose that counts as the map. It certainly is not a browser.
How big is the image? Does is only happen when a client connects, or does it still happen if you attempt to display the title screen later? Do you have client.preload_rsc set to 0? Does it happen when anybody logs in, or just the first person? Does it happen when logging in through DreamDaemon or just DreamSeeker?

Thats a lot of questions. Sorry. Just trying to figure out what it could be.
I have this happen fairly often with icons as well.

Seems like it is some kind of corruption of the game's cache.

It doesn't just happen with .PNG files but with .DMI as well.

My game allows players to upload their own icons but I have height and width limits as well as file size limits in place.

Occasionally their icons will return a null value for the height/width. The only way for them to fix this is to open the icon, change something in the image, slightly change a pixel's color or something, and save it. Loading this slightly edited icon will then function.

I've asked about it before and was only ever told it was some type of corruption in the header data, but never found any way to fix it.