ID:1173265
 
BYOND Version:498
Operating System:Windows 7 Ultimate
Web Browser:Firefox 18.0
Applies to:Dream Maker
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary: Me and Kidpaddle where working on our online store. We stored an icon into a list to later reference, when we tried to output that icon to the browser, we found out it won't show up, as it says couldn't access cache file.

The strange part is that if we generated the icon and the specified icon_state is missing within the file, the icon will show correctly.

Numbered Steps to Reproduce Problem:
I. Create a new DM file, a global list and a new verb.
II. Make the global list get an icon by using the icon() proc. And the verb to output the icon via the icon text macro.
var/list/myIcons = list(icon('MyIcon.dmi', "RealState")
client/verb/ShowIcon()
usr << browse("\icon[myIcons[1]]")

You will now note that the icon is not found, as the icon state was existing within the file.

III. Change the icon state we retrieved in step II, and re-compile.

IV. We will now note that the icon showed up correctly.

Expected Results: The icon to show under any circumstances.

Actual Results: The icon only showing if a missing icon_state is specified.

Does the problem occur:
Every time? Or how often? Every time I use this approach.
In other games? Not that I noticed.
In other user accounts? It happens in both accounts, so I would say this applicates to everyone.
On other computers? Of course it does.

When does the problem NOT occur? When you specify a missing icon_state within the icon() procedure.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? Would need to donwload one to test it, but as of now, I have no clue.

Workarounds:
To create a new dmi file with a blank icon state and specify a missing one.
The \icon macro doesn't function properly in browsers. You need to use browse_rsc() in order to place an image in the cache to later use in the browser.
Actually, LA, I've tried it. If the chosen icon_state exists, it doesn't work.
Yeah, thats why I posted it in the first hand, I already know browse_rsc, just tried to save some bandwitch using the existing resource pack, rather than transferring the icons constantly.

I firstly thought it was just my fault, but investigating a bit I came with this. o.o
Bumping with a Double-Post with some relevant info:

If you have two icon_states not named within the same file, and output it with browse_rsc() and browse(), theres the chance to see the icon as a movie, (or spritesheet), upon refreshing page.

client/verb/Test()
src << browse_rsc('MyBaseIcon.dmi',"base.png")
src << browse("<img src=\"base.png\">")
When I tested this, following your steps, it displayed "Unable to open cache file." whether the icon_state exists or not. This matches the reference, as LA mentioned:
Note that the \icon macro does not work in the mini-browser; it is only for text output

Are there any steps you might have left out?

As for DMIs displaying as a spritesheet in the browser when embedded as PNGs, that's expected behavior (and should always happen when there are multiple states/frames/dirs). This is because DMIs are really PNG files with some text comments describing how to translate the sprite sheet into states, frames, dirs, ect.

<edit>
Just tried embedding a DMI as a PNG, and it only seems to be displaying the first frame instead of the spritesheet. Are you doing these tests in a blank environment, or is there other code running that may be affecting things?
Here's probably a more proper way to do it and exhibits the issue.
        upload_icon(i as icon)
var/icon/b = icon(icon = i, icon_state = "c")
src << browse("<img src = \ref[fcopy_rsc(b)]>")


This is used with an icon that has state "c", it doesn't work. Now, if you remove the state assignment line, it works fine.
Also DC, I understand DMI's are similar to not say almost exact to PNG. What is not expected is it to appear as a spritesheet one a while, and show as a single frame when it feels like to, which was a bit weird at the moment of encountering the issue o.o
In response to Super Saiyan X
That's still giving me the same "Unable to open cache file" message, whether or not the icon has the state, and whether or not the state is specified.

A) Do you guys have an interface file, or are you just using the default skin?

B) If you clear your BYOND cache, does it still work?

The only way I've been able to get an icon to display in the browser is to use browse_rsc() and specify the FileName, and then use that FileName in an <img> src attribute:
mob
verb
upload_icon(i as icon)
src << browse_rsc(i,"test.png")
src << browse("<img src=\"test.png\">")


\ref (and consequently \icon) shouldn't work, as those use references to internal resources. The browser should only be able to load files existing in the cache directory...

If you store the HTML in a variable before using it in browse(), and do something like src << html_encode(html), what does the output look like for icons that work versus those that don't?
        upload_icon(i as icon)
var/icon/b = icon(icon = i, icon_state = "c")
var/html = {"<img src="\ref[fcopy_rsc(b)]">"}
src << html_encode(html)
src << browse(html)
</<>
In response to DarkCampainger
DarkCampainger wrote:
That's still giving me the same "Unable to open cache file" message, whether or not the icon has the state, and whether or not the state is specified.

A) Do you guys have an interface file, or are you just using the default skin?
No included interfaces.

B) If you clear your BYOND cache, does it still work?
Yes, I've tested it my way a bunch of different times with different methods.

The only way I've been able to get an icon to display in the browser is to use browse_rsc() and specify the FileName, and then use that FileName in an <img> src attribute:
mob
verb
upload_icon(i as icon)
src << browse_rsc(i,"test.png")
src << browse("<img src=\"test.png\">")

This works fine, because it's not an icon object.


\ref (and consequently \icon) shouldn't work, as those use references to internal resources. The browser should only be able to load files existing in the cache directory...

\ref should work fine. It works for interface elements. It works for browsers, since it's a reference to a cache entry returned by fcopy_rsc.

If you store the HTML in a variable before using it in browse(), and do something like src << html_encode(html), what does the output look like for icons that work versus those that don't?
        upload_icon(i as icon)
var/icon/b = icon(icon = i, icon_state = "c")
var/html = {"<img src="\ref[fcopy_rsc(b)]">"}
src << html_encode(html)
src << browse(html)
This exhibits the same issue.
</<>
In response to Super Saiyan X
Super Saiyan X wrote:
This works fine, because it's not an icon object.

Well, it works with a /icon object too:
        upload_icon3(i as icon)
var/state = input(src, "Pick a state") in icon_states(i)
var/icon/b = icon(icon = i, icon_state = state)
src << browse_rsc(b,"test.png")
src << browse("<img src=\"test.png\">")


Super Saiyan X wrote:
\ref should work fine. It works for interface elements. It works for browsers, since it's a reference to a cache entry returned by fcopy_rsc.

The interface is handled by Dream Seeker. However, the browser is an embedded IE instance, and I don't think it understands DS's references (eg how does it take <img src="[0xc000003]"> and stream the relevant icon out of DS's memory). I think fcopy_rsc() is referring to a separate cache (the dynamic rsc, as opposed to the %user%/cache directory)

This exhibits the same issue.

I know, I just wanted to see what the generated HTML looked like to see if it's really giving it a ref code or something else. Did it output something like above? ([0xc000003])
It outputs <img src="[0xc000002]">.

Anyways, I think I know why you're not getting the issue. (icon appearing correctly without a state, but not with)

The 'good' upload has to be the first upload (without specifying a state). If you do a bad one first (with a state), every subsequent upload doesn't work.

The way I specified earlier (when it works), the HTML file created in the BYOND cache has the contents: '<img src = icons.dmi>'

Edit:

The odd thing is, when you don't specify an icon_state, an icon is generated in the BYOND user cache. If you do, it doesn't.
browse_rsc() forces it in there, and assigns a new name to it no matter what.

Even if it's not a bug, it's inconsistent behavior.