Thursday, May 23, 2013

Dynamic loading of content in Emscripten (Packaging files and lazy loading)

It appears Emscripten allows two types of loading or at least did. The first type is where you package files with your build command. The compiled code then shows a nice download progress bar. Once it's loaded then your program runs. This is the majority of how I have seen the apps run. The other method lazy loading no longer works. Lazy loading was intended to work by synchronously requesting chunks of bytes. Say you need X bytes of a file, lazy loading would request these bytes via http and then wait on the call until those bytes were returned. Just like reading from a hard drive so everything seems to work the same right? Firefox and Chrome disabled this synchronous call or supporting technology used behind the hood of the engine. So lazy loading is unlikely to work for you. My thoughts to get around this are to load the file via javascript and then use a hook from the C code to get at that data. I will report back if I am able to do this.

2 comments:

  1. Hi, did you manage to get around this issue?

    ReplyDelete
  2. See my entry "Loading an external image into Emscripten in ARGB" and "Calling a C function from Javascript in your Emscripten program". In short - keep a global instance of your app, make a c++ function that can be called from javascript. Then use javascript to load the object and then call the c++ code which uses your global instance to store the data.

    ReplyDelete