Skip to content

Conversation

@bitbrain
Copy link
Contributor

@bitbrain bitbrain commented Apr 6, 2024

Screenshot 2024-04-06 133323


Closes #50

This PR aims to add support for web support via wasm.

Todo

  • update SConstruct to consider web as a platform
  • make scons platform=web pass & build libGodotFmod.web.template_debug.wasm32.wasm correctly
  • Update documentation for how to build for web (requires Emscripten)
  • Update Github Action to build for web
  • Solve issue around bank file scanning (specifically file callback logic https://github.com/utopia-rise/fmod-gdextension/blob/master/src/callback/file_callbacks.cpp)
  • Solve Uncaught TypeError: Module.FMOD_JS_MixerFastpathFunction is not a function onmessage when trying to play sounds

Known issues

@bitbrain
Copy link
Contributor Author

bitbrain commented Apr 11, 2024

This builds fine and GDExtension seems to load in Chrome (Firefox still does not work), but then it fails due to memory issues in the browser:

Screenshot 2024-04-11 062838
Screenshot 2024-04-11 063207

@2shady4u
Copy link
Contributor

Firefix also doesnt work for my SQLite plugin so I assume the issue with Firefox not working is on the side of godot-cpp itself.

@pmdevita
Copy link

pmdevita commented Aug 10, 2024

Hey I've been trying to take a stab at this recently to see if I can help and learn a bit more about C++. What version of emscripten and FMOD are you compiling with? From what I understand, w32 is the recommended format to work with now, why are you using the bitcode binaries instead?

EDIT: This thread on the FMOD forums seems to indicate that statically linking to the wasm binary like the build currently does will cause linking errors, I'm seeing the same ones right now. We may need to include the binaries instead like we do for the other platforms.

@JalikMetagram
Copy link

Hello ! I worked on a little game project using FMOD with Godot using utopia's addon. If you need a tester for this PR with a small game using fmod to make a web export don't hesitate reaching out !

@Evelyn-Hill
Copy link

Hey! wanted to checkup on progress of this/if it's still being worked on. If not, I'd be glad to pick up the torch and get this finished up at least on the code side of things.

@CedNaru
Copy link
Member

CedNaru commented Sep 14, 2024

Feel free to try your hands on it. It hasn't been touched in months.

@bitbrain
Copy link
Contributor Author

I originally raised the PR for this but have not worked on it ever since due to hitting blockers. If anyhbody can figure out how to make it work that would be brilliant.

@Evelyn-Hill
Copy link

I originally raised the PR for this but have not worked on it ever since due to hitting blockers. If anyhbody can figure out how to make it work that would be brilliant.

Could I ask what issues you ran into other than the Memory stuff listed above? I'm going to take a crack at it soon.

@BigOrangeBoy
Copy link

I use GoDot and FMOD and I would pay someone to finish this

@Lvl50Hornist
Copy link

I would also pay for this to be completed. xD Someone, anyone take my money.

@pmdevita
Copy link

pmdevita commented Dec 18, 2024

Opened a new thread on the forums, maybe this will help us get somewhere https://qa.fmod.com/t/emscripten-linking-errors/22429

EDIT: One of the FMOD devs said they are going to look into the situation, hopefully they will come up with some sort of solution for us

Just to add some extra info, this solution where we statically build the FMOD GDextension against the shared object library is actually against FMOD's EULA since we would technically be distributing a "tool for an end-user application". It seems a bit unfair that way, the only allowed option would be to compile FMOD into Godot, and all of that effort would be just for distributing Godot FMOD HTML5 games. I'm hoping we can dynamically link it like we do on the other platforms or (long shot but fingers crossed) they make some kind of exception in the EULA for us and other 3rd party engines.

@pmdevita
Copy link

pmdevita commented Mar 8, 2025

Update, as of 2.02.27, FMOD has started compiling the HTML5 build with position independent code -fPIC enabled! Builds against w32 now compile with no errors!

However, FMOD still doesn't work on the web due to some runtime errors and I'm struggling to get a readable traceback from it. I don't have much experience in C++/emscripten to begin with so if anyone is interested in helping, please let me know!

@fkeyzuwu
Copy link

fkeyzuwu commented May 6, 2025

Update, as of 2.02.27, FMOD has started compiling the HTML5 build with position independent code -fPIC enabled! Builds against w32 now compile with no errors!

However, FMOD still doesn't work on the web due to some runtime errors and I'm struggling to get a readable traceback from it. I don't have much experience in C++/emscripten to begin with so if anyone is interested in helping, please let me know!

hey, any updates on this? ❤️
also might be related to this - godotengine/godot#105369

they say Godot officially supports version 3.1.62 of emscripten, maybe worth a shot to try that one?

@fakemaxwell
Copy link

Sorry to "any updates?" this, but wanted to check and see if this was something that is potentially possible, or if it's a lost cause. I wish I knew anything about how it all worked to pitch in, but unfortunately I don't have the skillset. Happy to pitch in some funds if somebody is available to head it up.

@pmdevita
Copy link

Sorry for the delay, I got sort of discouraged at the time and just haven't circled back to yet in my side project rotation.

As far as the linked Godot issue, that was not an issue for me as I was building with Emscrypten 3.1 and (as far as I remember) I believe I was successful in building the web build for Godot, which I was attempting to do to enable extra debugging info.

When the build fails to launch in the browser, Godot suggests I compile with debug mode on, but I think after compiling both Godot and FMOD with debug enabled, I was still getting the exact same suggestion and the error message was no more usable. I'll try to take another crack at it soon.

@bitbrain
Copy link
Contributor Author

@pmdevita amazing, could you perhaps also share a branch of your progress? More eyes could then also take a look at it and we can figure this out together.

@pmdevita
Copy link

This branch https://github.com/pmdevita/fmod-gdextension/tree/web-support is the closest thing online to what I have right now, you want to build against a recent FMOD >2.02.27, <2.03 and you compile against the w32 binaries. I think it should no longer require messing with the LINKFLAGS. I'll try to update my branch sometime soon with my local changes

@pmdevita
Copy link

pmdevita commented Jul 15, 2025

Branch is now updated to master https://github.com/pmdevita/fmod-gdextension/tree/web-support-4.4

Rough instructions

  1. Be already familiar with building Godot or extensions (try building this for desktop if you haven't before)
  2. Install emscrypten emsdk 3.1+ (not 4!) and make sure you can run emcc from your terminal
  3. Clone the repo making sure the submodule godot-cpp inits (https://fmod-gdextension.readthedocs.io/en/latest/advanced/1-compiling/#compiling)
scons target=template_debug platform=web fmod_lib_dir=path/to/fmod threads=no verbose=yes

Path to FMOD is the path to the root directory of the unpacked HTML5 SDK. FMOD does not support threads in HTML5 (yet, hopefully).

If all goes well, it should build without error or warning, whereas previously it would complain a lot about -fPIC. Exporting from Godot and running it in the browser will give you this error

image

This is around where I got stumped, if I did somehow make it past this error (and I'm not sure I did) I was met with an equally as useless error about enabling verbose debugging or something. Does anyone know how to compile with -sAssertions? From my rough chaotic experience in building random C/C++ projects, I also wonder if this is a red herring too.

I think we should be building with env.Append(LIBS=[libfmodstudio]) but it fails with the error wasm-ld: error: unable to find library -lfmodstudioL_wasm. The SDK will also still "build" even without giving it the LINKFLAGS with the path to the studio binary but produces a much smaller (probably wrong) binary. I'm really not sure what of these flags was supposed to be set other than CPPPATH and LIBPATH.

FMOD has some docs on HTML5 here but they are inconsistent with what the SDK presents and are not very clear otherwise.

@sphynx-owner
Copy link

sphynx-owner commented Dec 1, 2025

Hello, I am investigating fmod with godot on the web, and naturally reached this pr. So if I understand, @pmdevita has the most progress, but work is generally stale. What is the feasibility of reaching something working? How much work would be needed? Is it just about figuring out the SConstruct? Would modification to source be required?

@bitbrain
Copy link
Contributor Author

bitbrain commented Dec 2, 2025

@sphynx-owner I have attempted continuing the work myself but hit a brickwall again. Fixing the SConstruct is not a big deal, I am even able to run the game in the web. The only issue is that no audio plays because banks cannot be loaded. This is due to the custom bank loading logic this extension has: in order to load banks properly, we are running our own custom bank loader but that one won't work in the web. I had the idea to use preprocessor directives to do a cheeky if-else and disable any code that would be incompatible when building for web and using the native behaviour instead.

@sphynx-owner
Copy link

@bitbrain I appreciate your resopnse. In fact, this sounds very promising. I have a few questions then:

  1. why do we have custom bank loading logic?
  2. what could be the reason that it fails on the web build?

Also, perhaps unrelated, but I came across a quote from the FMod documentation:

Running FMOD as HTML5 on the web is made possible by having a web server host and deliver the JavaScript content to the client web browser.

Is this related to bank loading logic? does that mean that every game using fmod on the web will need a dedicated server for content streaming?

@sphynx-owner
Copy link

Where can I find your latest progress?

@pmdevita
Copy link

pmdevita commented Dec 2, 2025

@bitbrain Did you continue it from my work? How did you get it to not crash at launch? I figured we'd have to revisit the bank loading, I think your idea with the preprocessors makes sense. We're gonna need a web specific loader.

For @sphynx-owner I believe we have custom bank loading logic so that we can store banks in the Godot game bundle file.

@bitbrain
Copy link
Contributor Author

bitbrain commented Dec 2, 2025

@sphynx-owner let me dig out the changes and push them here.

Did you continue it from my work?

@pmdevita yes :)

Screenshot_2025-10-07_211402

This is as far as I got: the demo project runs in the browser, but with no sound and a ton of console errors.

@sphynx-owner
Copy link

I see. Thank you for digging this out for me.

@sphynx-owner
Copy link

sphynx-owner commented Dec 2, 2025

I don't mean to rush, but do you have a PR that I can clone and have a look at myself @bitbrain? You might have pushed already and I just don't know where to look

@sphynx-owner
Copy link

I believe I got pretty close to having a compiled web bulid, but yet so far away. I got @pmdevita's branch, and followed his instructions, however I am getting this error when trying to compile. I am on windows so I am already shooting in the dark here:
image

@sphynx-owner
Copy link

Update: I got the latest fmod gdextension, and applied the same changes that @pmdevita had done in his fork
I am basically in the same state as described in his message, errors and everything, but with the latest gdextension version, fmod 2.03.06, and the latest version of emscripten. @bitbrain any updates? You said you had further progress using @pmdevita's work, I could try and pick up from where you left.

@bitbrain
Copy link
Contributor Author

bitbrain commented Dec 6, 2025

@sphynx-owner I pushed changes to this branch so it is up to date with master branch and scons platform=web now builds successfully. However, it still won't work when exporting a web build due to the issues discussed before.

The required structure in libs is:

libs/fmod/api <- probably should be renamed to `web` for consistency
    core/*
    fsbank/*
    studio/*

My toolchain:

$ scons --version
SCons by Steven Knight et al.:
        SCons: v4.10.0.b3e979a3e42c43b91f7624895910afb869a19806, Thu, 02 Oct 2025 10:16:02 -0700, by bdbaddog on M1Dog2021
        SCons path: ['C:\\Users\\mgonz\\scoop\\apps\\python\\current\\Lib\\site-packages\\SCons']
Copyright (c) 2001 - 2025 The SCons Foundation
$ emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.17 (bb11bae9af3a6551132655a0908f86889d2d423b)
Copyright (C) 2025 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ --version
g++.exe (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@sphynx-owner
Copy link

@bitbrain thanks for the update. What FMOD version do I get? because 2.03.06 does not have the upstream directory anymore.

@sphynx-owner
Copy link

I would also like to clarify, you were able to run the game in the browser (albeit without sound banks loading). Were you doing that from the editor with the "run-in-browser" button?

@sphynx-owner
Copy link

My main concern right now is that I am not seeing any significant difference in your changes to those that @pmdevita did, yet you were able to enter the game without an -sAssertion error. This leads me to believe your success is due to toolchain specific setup.

@bitbrain
Copy link
Contributor Author

bitbrain commented Dec 6, 2025

@sphynx-owner I had to tweak it slightly, as without it, I got the same error as @pmdevita. Can you join the Discord server? We can debug the issues you are facing together in the #gdextension channel: https://discord.gg/nS34H6fY

@bitbrain
Copy link
Contributor Author

bitbrain commented Dec 7, 2025

Bank loading seems to work fine now. However, still no sound. The main issue right now is that gdextension .wasm is built as a side module because the main module is Godot itself, but FMOD's HTML5 setup assumes it is always run from a main module, so it leads to "visibility" problems of glue code. Raised the issue here to ask for assistance from the FMOD team on this matter.

@RafaelVidaurre
Copy link

I found a dirty workaround to get this working on @sphynx-owner 's branch here

Here's a copy-paste from the message I left on the Godot Fmod Discord:


Maybe this will shed some light onto whats going on with the banks, but I managed to get the HTML5 build to run by doing this:

  1. Served the bank files from an http server, such that paths are foobar.com/assets/* (e.g. with a local server http://localhost:<port>/assets
  2. On the index.html file, right before the game starts. I added explicit calls to load the current banks
Promise.all([
            engine.preloadFile('assets/Banks/Master.bank', 'assets/Banks/Master.bank'),
            engine.preloadFile('assets/Banks/Master.strings.bank', 'assets/Banks/Master.strings.bank'),
            engine.preloadFile('assets/Banks/Dialogue_CN.bank', 'assets/Banks/Dialogue_CN.bank'),
            engine.preloadFile('assets/Banks/Dialogue_EN.bank', 'assets/Banks/Dialogue_EN.bank'),
            engine.preloadFile('assets/Banks/Dialogue_JP.bank', 'assets/Banks/Dialogue_JP.bank'),
            engine.preloadFile('assets/Banks/Music.bank', 'assets/Banks/Music.bank'),
            engine.preloadFile('assets/Banks/SFX.bank', 'assets/Banks/SFX.bank'),
            engine.preloadFile('assets/Banks/Vehicles.bank', 'assets/Banks/Vehicles.bank'),
          ]).then(() => {
            engine
              .startGame({
                onProgress: function (current, total) {
                  if (current > 0 && total > 0) {
                    statusProgress.value = current;
                    statusProgress.max = total;
                  } else {
                    statusProgress.removeAttribute('value');
                    statusProgress.removeAttribute('max');
                  }
                },
              })
              .then(() => {
                setStatusMode('hidden');
              }, displayFailureNotice);
          });

This made the banks available to the game and it seems to function as intended

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FMOD web support (HTML5)