--preload-file what is the path in the MEMFS?

22 views
Skip to first unread message

キャロウ マーク

unread,
Jul 20, 2019, 1:15:41 PM7/20/19
to emscripten-discuss
I have —preload-file testimages on my emcc command. testimages is a directory of images. I am trying to load these in my app with, e.g, fopen(”testimages/image.ktx2”, …). The open is failing. I am wondering if perhaps the files are being put into MEMFS without the testimages parent directory. I have not found any documentation beyond the very simple example in the tutorial which only pre-loads a single file. So no help there.

Regards

-Mark
signature.asc

キャロウ マーク

unread,
Jul 20, 2019, 4:28:46 PM7/20/19
to emscripten-discuss


> On Jul 20, 2019, at 10:15, キャロウ マーク <git...@callow.im> wrote:
>
> I have —preload-file testimages on my emcc command. testimages is a directory of images. I am trying to load these in my app with, e.g, fopen(”testimages/image.ktx2”, …). The open is failing. I am wondering if perhaps the files are being put into MEMFS without the testimages parent directory. I have not found any documentation beyond the very simple example in the tutorial which only pre-loads a single file. So no help there.
>

If my reading of the packaging documentation is correct, “testimages/foo” should be readable as “testimages/foo” in the MEMFS. However I am getting file not found error. How can I list the files that have been included in the .data file after compilation? I’m sure there used to be a way when I was using Emscripten a few years ago but I couldn’t find any mention in the documentation now.

Regards

-Mark
signature.asc

Alon Zakai

unread,
Jul 22, 2019, 1:07:58 PM7/22/19
to emscripte...@googlegroups.com
I think it should work as you expect. For example,

#include <stdio.h>
int main() {
  printf("%p\n", fopen("src/webGLWorker.js", "rb"));
}

built with

./emcc a.cpp --preload-file src/ -o a.html

in the emscripten root directory will succeed to fopen that file (which indeed exists under src/).

You can inspect the output JS file to see the preloaded file code. For example in the output from that command, it contains this metadata for that file that is opened:

{"start": 2376860, "audio": 0, "end": 2419578, "filename": "/src/webGLWorker.js"}

Some possible issues might be if you are in another directory, or the preloading failed due to a network error, etc. (can use the network tab in devtools to debug stuff like this).

- Alon


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/AEC53EAA-17D6-4CF6-B4B2-9B41D3077DCE%40callow.im.

キャロウ マーク

unread,
Jul 22, 2019, 1:56:13 PM7/22/19
to emscripten-discuss


On Jul 22, 2019, at 10:07, Alon Zakai <alon...@gmail.com> wrote:

I think it should work as you expect. For example,

Thanks Alon. It did. I was caught out by the browser cache again serving an old version of the code.

Regards

    -Mark



signature.asc
Reply all
Reply to author
Forward
0 new messages