FMOD craches on load on NW.js

FMOD crashes on load on NW.js because it detects NW.js as a “Node Environment” and assumes __dirname exists but it appears that it does not in NW.js
Maybe it can be replaced with “process.cwd()” I suppose.

In general, I think it’s a good idea to at least do a tryCatch on the environment detection code and fallback to non Node environment in case it did not work out.

Here is the error:
ReferenceError: __dirname is not defined

And here is the code concerned by this:
if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require(“path”).dirname(scriptDirectory) + “/”;
} else {
scriptDirectory = __dirname + “/”;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

Here is my code that seems to have fixed the issue:

ENVIRONMENT_IS_NODE =
  typeof process === "object" &&
  typeof process.versions === "object" &&
  typeof process.versions.node === "string";
if (ENVIRONMENT_IS_NODE) {
  try {
    if (__dirname === undefined) ENVIRONMENT_IS_NODE = false;
  } catch (error) {
    ENVIRONMENT_IS_NODE = false;
  }
}

Hi,

Thank you for sharing the solution.

What version of FMOD are you using? Could I get some reproduction steps that cause the issue?

Thanks

I am using the latest fmodStudio wasm version (not large, although I suppose it would also happen with large) and I exported using the NW.js export from the Construct 3 engine.

Here is the build that failed:

1 Like

Hi,

Thank you for the project, what version of FMOD are you using?

I will pass this onto our development team to look into further, if there are any updates I will update the forum.

Hi, I used FMOD v2.02.20

1 Like

Hi,

Thank you for the information.