Skip to content

Latest Emscripten 2.0.33 works well, except file loading. [solved] #6781

Closed

Description

@Jonathhhan

It was possible to compile with the latest Emscripten, for that I had to recompile the OF libs (FreeImage or freetype for example) with the current Emscripten and made some other small changes like using c++17 and std filesystem instead of boost (boost had an undefined symbol).
I guess the issue now has to do with the glm qualifier glm::qualifier)0>&, this is the Java Script error message for the imageSubsectionExample (everything compiles fine):
imageSubsectionExample.html:1 emscripten_set_main_loop_timing: Cannot set timing mode for main loop since a main loop does not exist! Call emscripten_set_main_loop first to set one up. printErr @ imageSubsectionExample.html:1 imageSubsectionExample.html:1 Aborted(native code called abort()) printErr @ imageSubsectionExample.html:1 imageSubsectionExample.js:1 Uncaught RuntimeError: Aborted(native code called abort()) at abort (imageSubsectionExample.js:1:34496) at _abort (imageSubsectionExample.js:1:119651) at std::__2::__throw_failure(char const*) (imageSubsectionExample.wasm:0x362df2) at std::__2::__fs::filesystem::__canonical(std::__2::__fs::filesystem::path const&, std::__2::error_code*) (imageSubsectionExample.wasm:0x380f6f) at ofToDataPath(std::__2::__fs::filesystem::path const&, bool) (imageSubsectionExample.wasm:0x55a2d) at ofApp::setup() (imageSubsectionExample.wasm:0x22653) at ofNode::onParentOrientationChanged(glm::qua<float, (glm::qualifier)0>&) (imageSubsectionExample.wasm:0x4638a) at std::__2::__function::__func<std::__2::shared_ptr<of::priv::Function<ofKeyEventArgs, std::__2::recursive_mutex> > ofEvent<ofKeyEventArgs, std::__2::recursive_mutex>::make_function<ofMainLoop>(ofMainLoop*, void (ofMainLoop::*)(ofKeyEventArgs&), int)::'lambda'(void const*, ofKeyEventArgs&), std::__2::allocator<std::__2::shared_ptr<of::priv::Function<ofKeyEventArgs, std::__2::recursive_mutex> > ofEvent<ofKeyEventArgs, std::__2::recursive_mutex>::make_function<ofMainLoop>(ofMainLoop*, void (ofMainLoop::*)(ofKeyEventArgs&), int)::'lambda'(void const*, ofKeyEventArgs&)>, bool (void const*, ofKeyEventArgs&)>::operator()(void const*&&, ofKeyEventArgs&) (imageSubsectionExample.wasm:0x4c0d6) at ofEvent<ofHttpResponse, std::__2::recursive_mutex>::notify(ofHttpResponse&) (imageSubsectionExample.wasm:0x2a046) at ofCoreEvents::notifySetup() (imageSubsectionExample.wasm:0x4cb73)
Is there a way to solve whether the boost, the glm or the std filesystem issue, so that is possible to load data with OF and the latest Emscripten (everything else seems to work fine)?

Activity

  1. Jonathhhan commented on Nov 12, 2021

    @Jonathhhan
    ContributorAuthor

    This is the Java Script error message if I compile with boost (even if there is no file to load):

    advanced3dExample.html:1 missing function: 
    _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_
    printErr @ advanced3dExample.html:1
    advanced3dExample.html:1 Aborted(-1)
    printErr @ advanced3dExample.html:1
    advanced3dExample.js:1 Uncaught RuntimeError: Aborted(-1)
        at abort (advanced3dExample.js:1:34320)
        at __ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_ (advanced3dExample.js:1:47694)
        at boost::filesystem::absolute(boost::filesystem::path const&, boost::filesystem::path const&) (advanced3dExample.wasm:0x9716b)
        at main (advanced3dExample.wasm:0x1c5b5)
        at advanced3dExample.js:1:35039
        at callMain (advanced3dExample.js:1:277462)
        at doRun (advanced3dExample.js:1:278046)
        at advanced3dExample.js:1:278201
    

    And interestingly, if I compile with std filesystem and -O1 instead of -O3 the glm error is gone (which enables for example the polygonExample to work):

    imageSubsectionExample.html:1 emscripten_set_main_loop_timing: Cannot set timing mode for main loop since a main loop does not exist! Call emscripten_set_main_loop first to set one up. printErr @ imageSubsectionExample.html:1 imageSubsectionExample.html:1 Aborted(native code called abort()) printErr @ imageSubsectionExample.html:1 imageSubsectionExample.js:201 Uncaught RuntimeError: Aborted(native code called abort()) at abort (imageSubsectionExample.js:1596:10) at _abort (imageSubsectionExample.js:5377:2) at void std::__2::__fs::filesystem::__throw_filesystem_error<std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >&, std::__2::__fs::filesystem::path const&, std::__2::__fs::filesystem::path const&, std::__2::error_code const&>(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >&, std::__2::__fs::filesystem::path const&, std::__2::__fs::filesystem::path const&, std::__2::error_code const&) (imageSubsectionExample.wasm:0x3d5671) at std::__2::__fs::filesystem::detail::(anonymous namespace)::ErrorHandler<std::__2::__fs::filesystem::path>::report(std::__2::error_code const&) const (imageSubsectionExample.wasm:0x3d561a) at std::__2::__fs::filesystem::__canonical(std::__2::__fs::filesystem::path const&, std::__2::error_code*) (imageSubsectionExample.wasm:0x3d54df) at ofToDataPath(std::__2::__fs::filesystem::path const&, bool) (imageSubsectionExample.wasm:0x4d9d7) at ofLoadImage(ofPixels_<unsigned char>&, std::__2::__fs::filesystem::path const&, ofImageLoadSettings const&) (imageSubsectionExample.wasm:0x10179) at ofImage_<unsigned char>::load(std::__2::__fs::filesystem::path const&, ofImageLoadSettings const&) (imageSubsectionExample.wasm:0x10a8c) at ofApp::setup() (imageSubsectionExample.wasm:0x9248) at ofBaseApp::setup(ofEventArgs&) (imageSubsectionExample.wasm:0x330e2)
    So my question is: Is there is a way to make any of the filesystems work with this Emscripten version?

  2. Jonathhhan commented on Nov 12, 2021

    @Jonathhhan
    ContributorAuthor

    I comiled boost again, and now OF works with boost and Emscripten 2.0.33...
    Can add what I changed exactly for that, but basically I recompiled the necessary OF libs with Apothecary Emscripten 2.0.33.
    Edit: Also had to change some other stuff, but now it seems to work like the last versions...

  3. changed the title [-]Latest Emscripten 2.0.32 works well, except file loading.[/-] [+]Latest Emscripten 2.0.32 works well, except file loading. [solved][/+] on Nov 12, 2021
  4. Jonathhhan commented on Nov 13, 2021

    @Jonathhhan
    ContributorAuthor

    Those are the additional changes (these changes need to be added, too: #6758):

    library_html5video.js (remove type)

    html5video_player_pixel_format: function(id){
        return allocate(intArrayFromString(VIDEO.players[id].pixelFormat), ALLOC_STACK);
    },
    
    html5video_grabber_pixel_format: function(id){
        return allocate(intArrayFromString(VIDEO.grabbers[id].pixelFormat), ALLOC_STACK);
    },
    

    index.html (keyevents)

    <canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>
    

    library_html5.js(emsdk remove __ from getBoundingClientRect)

        #if !DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
        if (Module['canvas']) {
          var rect = getBoundingClientRect(Module['canvas']);
          HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasX / 4 }}}] = (e.clientX - rect.left) * (Module['canvas'].width / rect.width);
          HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasY / 4 }}}] = (e.clientY - rect.top) * (Module['canvas'].height / rect.height);
        } else { // Canvas is not initialized, return 0.
          HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasX / 4 }}}] = 0;
          HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.canvasY / 4 }}}] = 0;
        }
    #endif
        var rect = getBoundingClientRect(target);
        HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.targetX / 4 }}}] = (e.clientX - rect.left) * (target.width / rect.width);
        HEAP32[idx + {{{ C_STRUCTS.EmscriptenMouseEvent.targetY / 4 }}}] = (e.clientY - rect.top) * (target.height / rect.height);
    

    config.emscripten.default.make (add DYNCALLS=1 and BINARYEN_EXTRA_PASSES=--one-caller-inline-max-function-size=1)

    PLATFORM_LDFLAGS = -Wl,--gc-sections --preload-file bin/data@data --emrun -s DYNCALLS=1 -s MAX_WEBGL_VERSION=2 -s WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1 -s BINARYEN_EXTRA_PASSES=--one-caller-inline-max-function-size=1

  5. changed the title [-]Latest Emscripten 2.0.32 works well, except file loading. [solved][/-] [+]Latest Emscripten 2.0.33 works well, except file loading. [solved][/+] on Nov 13, 2021
  6. roymacdonald commented on Nov 19, 2021

    @roymacdonald
    Contributor

    hey @Jonathhhan Thanks for all this.
    Can you push to your OF fork all this changes so it is easier to check it and not having to go through all this issue and manually changing stuff.?

  7. Jonathhhan commented on Nov 19, 2021

    @Jonathhhan
    ContributorAuthor

    @roymacdonald yes, of course. I will do that the next days.

  8. roymacdonald commented on Nov 19, 2021

    @roymacdonald
    Contributor

    after installing emscripten 2.0.33 I cant compile as it complains the following:

    error: undefined symbol: _ZN24ofxEmscriptenSoundStreamC1Ev (referenced by top-level compiled C/C++ code)
    error: undefined symbol: tessDeleteTess (referenced by top-level compiled C/C++ code)
    error: undefined symbol: tessNewTess (referenced by top-level compiled C/C++ code)
    
    

    @Jonathhhan
    it is not seeing ofxEmscriptenSoundStream. did you add it somewhere? the other errors are for tess2.
    thanks

  9. roymacdonald commented on Nov 20, 2021

    @roymacdonald
    Contributor

    I was able to get it to compile. I mostly needed to recompile the core lib dependencies.

  10. Jonathhhan commented on Nov 21, 2021

    @Jonathhhan
    ContributorAuthor

    @roymacdonald thats nice. It would be great if you can help me to get the ofxPd examples to run with Emscripten (for using it with AudioWorklets). ofxPd works for me as part of ofxOfelia with Emscripten and standalone, but somehow not with Emscripten without ofxOfelia...

  11. roymacdonald commented on Nov 21, 2021

    @roymacdonald
    Contributor

    Sure, no problem.
    Let me get it to run the window properly. Did you manage to get GLES 2 shaders to work? I have not. I am modifying ofxAppEmscriptenWindow to make it work properly based on some examples that emscripten has.
    once I get that to work it my guess is that it shouldnt be much trouble to get audio to work as I know very well how audio works within OF.

  12. Jonathhhan commented on Nov 21, 2021

    @Jonathhhan
    ContributorAuthor

    Yes, GLES2 is working now (my example https://gameoflife3d.handmadeproductions.de/ actually uses shaders for the grid). I think its part of my changes.
    #6758

    changing this:

    EGLint contextAttribs[] = { EGL_CONTEXT_MAJOR_VERSION, 3, EGL_NONE, EGL_NONE };
    std::vector attribList =
    {
    EGL_RED_SIZE, EGL_DONT_CARE,
    EGL_GREEN_SIZE, EGL_DONT_CARE,
    EGL_BLUE_SIZE, EGL_DONT_CARE,
    EGL_ALPHA_SIZE, EGL_DONT_CARE,
    EGL_DEPTH_SIZE, EGL_DONT_CARE,
    EGL_STENCIL_SIZE, EGL_DONT_CARE,
    EGL_SAMPLE_BUFFERS, EGL_DONT_CARE,
    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
    EGL_NONE
    };

    in https://github.com/Jonathhhan/openFrameworks/blob/master/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp and adding the flag -s USE_WEBGL2=1 to config.emscripten.default.mk enables webgl2 without editing any Emscripten file (in addition I use -s WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1 for backwards compatibility with webgl1 https://emscripten.org/docs/optimizing/Optimizing-WebGL.html).

  13. Jonathhhan commented on Nov 21, 2021

    @Jonathhhan
    ContributorAuthor

    For AudioWorklets and SharedArraybuffer all used libs (for most things boost is enough) and also OF need to be compiled with -s USE_PTHREAD=1 or multi thread support. The pthread compiled libs work also if pthread isnt used.

  14. roymacdonald commented on Nov 21, 2021

    @roymacdonald
    Contributor

    @Jonathhhan I tried out your changes and cloned your OF repo, but it was not working. Maybe I missed something.
    Although I got it to work by changing a lot of other things and making it rely more on the emscripten functions. Maybe I messed up something when trying to get it to compile. I will go back and start over now that I have the necesary libs compiled and working. I will let you know how it goes. c
    cheers

  15. 66 remaining items

  16. Jonathhhan commented on Feb 7, 2022

    @Jonathhhan
    ContributorAuthor

    Hey @ofTheo and @roymacdonald, thats great news.

    I tried the url stuff from ofImage, but without luck.
    But urls do work if I replace audioPlayer.load(ofToDataPath(fileName) with audioPlayer.load(fileName).
    With the first one I can load files from the filesystem. Same for the video player.
    Maybe that helps.

    And I removed loadUrl()...

    And here is the branch: https://github.com/Jonathhhan/openFrameworks/tree/AudioWorklet

    I also made the audio context and the fft global (would also be possible to have a seperate fft for every sound id)...
    I hope I didnt break too much... ;)
    But I have all the older steps here if I should revert something...
    And of course, take what you think makes sense and if you have any questions I am happy to answer.
    Best.

  17. Jonathhhan commented on Feb 8, 2022

    @Jonathhhan
    ContributorAuthor

    Actually the sound player works with url and local file with this methods:

    	bool load(const std::filesystem::path& fileName, bool stream = false);
    	bool load(const std::string& fileName, bool stream = false);
    

    Somehow it does not work for the video player...

  18. Jonathhhan commented on Feb 8, 2022

    @Jonathhhan
    ContributorAuthor

    This works for the video player (but maybe not a nice solution):

    bool ofxEmscriptenVideoPlayer::load(const std::string fileName){
    	if (ofFile::doesFileExist(ofToDataPath(fileName))){
    		html5video_player_load(id, ofToDataPath(fileName).c_str());
    		return true;
    	} else {
    		html5video_player_load(id, fileName.c_str());
    		return true;
    	}
    }
    

    I updated the branch, video and audio player have the method above now. This way I dont have to change a lot.
    You can remove or change it if it is not save.

  19. roymacdonald commented on Feb 8, 2022

    @roymacdonald
    Contributor

    Hi @Jonathhhan
    This is the chunk of code you need in order to tell if it is an URL or not. I think there should be an OF function wrapping this up. It can be quite handy.

    #include "uriparser/Uri.h"
    
    	auto uriStr = fileName.string();
    	UriUriA uri;
    	UriParserStateA state;
    	state.uri = &uri;
    
    	if(uriParseUriA(&state, uriStr.c_str())!=URI_SUCCESS){
    		const int bytesNeeded = 8 + 3 * strlen(uriStr.c_str()) + 1;
    		std::vector<char> absUri(bytesNeeded);
    	#ifdef TARGET_WIN32
    		uriWindowsFilenameToUriStringA(uriStr.c_str(), absUri.data());
    	#else
    		uriUnixFilenameToUriStringA(uriStr.c_str(), absUri.data());
    	#endif
    		if(uriParseUriA(&state, absUri.data())!=URI_SUCCESS){
    			ofLogError("ofImage") << "loadImage(): malformed uri when loading image from uri " << _fileName;
    			uriFreeUriMembersA(&uri);
    			return false;
    		}
    	}
    	std::string scheme(uri.scheme.first, uri.scheme.afterLast);
    	uriFreeUriMembersA(&uri);
    
    	if(scheme == "http" || scheme == "https"){
                    // LOAD FROM URL. 
    		//return ofLoadImage(pix, ofLoadURL(_fileName.string()).data);
    
    	}
    
    	std::string fileName = ofToDataPath(_fileName, true);
    //LOAD FROM FILESYSTEM
    

    I will go through all the changes, updates and upgrades you have done and get back to you.
    cheers

  20. Jonathhhan commented on Feb 8, 2022

    @Jonathhhan
    ContributorAuthor

    @roymacdonald thanks a lot. And just to mention: The old html5audio_stream_create method is not implemented in my branch yet, but I guess it can be easily replaced...
    Without replacing it the stream works only with audioWorklet (but everything else should work independently from that).

  21. Jonathhhan commented on Feb 8, 2022

    @Jonathhhan
    ContributorAuthor

    Last update for now. The video player works now with url check (but I had to add "blob" to if(scheme == "http" || scheme == "https" || scheme == "blob" )). And the audio player with those 2 methods (because the url check didnt work there somehow - because the file / url is send as a std::filesystem::path and not as a std::string):

    	bool load(const std::filesystem::path& fileName, bool stream = false);
    	bool load(const std::string& fileName, bool stream = false);
    

    And here are some of the updated examples: https://github.com/Jonathhhan/ofEmscriptenExamples

    @ofTheo

    Just needed an extra header include and the C++17 flag in the end.

    Thats nice. I can confirm that it works, just needed to add your changes from ofConstants.h, ofFileUtils.cpp and ofUtils.h...

  22. Jonathhhan commented on Feb 15, 2022

    @Jonathhhan
    ContributorAuthor

    Here are some good news regarding the future of Emscripten and Audioworklets (at the end of the discussion): emscripten-core/emscripten#12502 (comment)

  23. Jonathhhan commented on Mar 4, 2022

    @Jonathhhan
    ContributorAuthor

    Just found another inconsistency between ofVideoPlayer and ofEmscriptenVideoPlayer with getDuration().
    With ofVideoPlayer I get values between 0 and 1, while with ofEmscriptenVideoPlayer I get the duration in seconds.

  24. roymacdonald commented on Mar 5, 2022

    @roymacdonald
    Contributor

    duration between 0 and 1 sounds like a bug? Although what you get is dependent on the platform you are using. On which platform did you see this?

  25. Jonathhhan commented on Mar 5, 2022

    @Jonathhhan
    ContributorAuthor

    Its Ubuntu, and I am sorry, I meant getPosition() of course...

  26. ranjithshegde commented on May 21, 2022

    @ranjithshegde

    I was able to get it to compile. I mostly needed to recompile the core lib dependencies.

    @roymacdonald I have the same errors as you. Could you please inform me what is it that you recompiled ?

  27. roymacdonald commented on May 21, 2022

    @roymacdonald
    Contributor

    I was able to get it to compile. I mostly needed to recompile the core lib dependencies.

    @roymacdonald I have the same errors as you. Could you please inform me what is it that you recompiled ?

    I really cant recall. But i think that I recompiled emscripten using apothecary, maybe i had to recompile some other things using apothecary as well. That is what would make sense to me

  28. ranjithshegde commented on May 22, 2022

    @ranjithshegde

    @roymacdonald Thanks for your response. Sadly I dont know what apothecary is. I checked the git repo and it seems like there are some scripts in there, specific to emscripten was just a method to install it in docker.

    Could you please point me towards any resources to understand what that repo is? Or how I would use them?

  29. roymacdonald commented on May 22, 2022

    @roymacdonald
    Contributor

    @ranjithshegde ah sorry. Apothecary is an openframeworks tool for keeping track and updating the libraries it uses. It is in github.com/openframeworks/apothecary
    Just download that repo into scripts/apothecary and run from there. What you need to do is to find the emscripten "formula", which is also inside the scripts folder and change the version to the latest one and run apothecary so it updates emscripten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions