Search for a string snippet "{{{ makeDynCall(" in Emscripten's src/
subdirectory for examples how to call a C/C++ function pointer from a
JS library. For example here:
https://github.com/emscripten-core/emscripten/blob/a38a72af8a75996fce5e27fcfb45f17ac38a0ce6/src/library_html5.js#L2723In JavaScript "delete image_from_handle;" for a variable is a no-op. The only syntax is "delete dict[key];" which will remove key from JS object dict. You can try first setting an image.src to an empty string ''; and then dropping all references to it, a smart browser should be able to drop the transfer then, if it has not yet finished. For explicit control, you could do a Fetch to an object URL, though that is a bit more involved code flow. ma 15. helmik. 2021 klo 17.54 'Phil Endecott' via emscripten-discuss ([email protected]) kirjoitti: > > Thanks everyone for your useful replies. > > Jukka Jylänki wrote: > > See here for a small example: https://github.com/juj/webgl_render_test > > , in particular this function that does the uploading: > > https://github.com/juj/webgl_render_test/blob/bb517e34dfaa13404feaa8a5ba8bf42c32581c44/src/library_js.js#L32 > > Right, that's close to what I need. I have a couple of questions: > > 1. Can anyone suggest how I can add a callback from the Javascript > to the C++ when the texture is loaded? I can't see a simple JS > call to which I can pass a C function pointer. (Or something > using a std::function?) > > 2. Any ideas about how to cancel an in-progress load? Maybe > deleting the Image object will abandon any in-progress download? > > Pseudo-code: > > // fetch_texture.js > > fetch_texture: function(url, texturenum, callback) > { > url = UTF8ToString*url); > const texture = GL.textures[texturenum]; > const image = new Image(); > image.onload = function() { > GLctx.bindTexture(GLctx.TEXTURE_2D, texture); > GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, > GLctx.UNSIGNED_BYTE, image); > callback(); // <---- ??? > }; > image.src = url; > return handle_to_image; // <--- ??? > } > > cancel_fetch_texture: function(handle) > { > delete image_from_handle; // ???? > } > > // fetch_texture.hh > > extern "C" { > handle_t fetch_texture(const char* url, int texturenum, void(*callback)()); > void cancel_fetch_texture(handle_t handle); > }; > > > Many thanks, Phil. > > > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/emscripten-discuss/1613404449510%40dmwebmail.dmwebmail.chezphil.org. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CA%2B6sJ-0iUf47Rt%2Bu3GJxZK82nig3CE9vO-rxAMzLab08dZYT3g%40mail.gmail.com.
