Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: failed to init the steamworks API #111

Open
chostett opened this issue Jul 29, 2023 · 18 comments
Open

Error: failed to init the steamworks API #111

chostett opened this issue Jul 29, 2023 · 18 comments

Comments

@chostett
Copy link

Hi there! We're (my co-dev and I) are currently using your library for our game, built in Electron and we're having issues connecting to Steamworks API. The error message we're getting is "Error: failed to init the steamworks API."

We've tried:

  • Version 0.3.0; the game opens and crashes with a segfault (tested on Mac 13.4.1 Ventura)
  • Version 0.2.2; shows "Error: failed to init the steamworks API" message
  • Version 0.1.0; same result as 0.2.2.

This might be related to this issue:
#65

We've read the Steamworks documentation and made sure that the “.dylib” file is present, and the “steam_appid.txt” is included.

I don't know what else to try. Could you help us?

@dfabulich
Copy link
Contributor

There's an example test electron project checked into this repository, in the test/electron directory.

The easiest way to test it is to copy the entire test/electron folder to a separate directory outside the repository, and edit package.json, changing the line "steamworks.js": "../.." to "steamworks.js": "0.3.0". Run npm install in the electron folder, and then launch the Steam client app, and then npm start.

(Note that you do have to launch the Steam client app yourself manually before launching the Electron app; the Steamworks API is designed to communicate with the Steam client app process to do its work.)

On my macOS Ventura 13.4.1 machine, the test Electron app launches without error and displays my Steam user name in the UI of the Electron app.

Note what I didn't have to do: I didn't have to include my own copy of the .dylib (because steamworks.js provides its own copy), and I didn't have to create a steam_appid.txt file, because renderer.js hardcodes a Steam App ID as app ID 480, which is the App ID of Steam's example game, SpaceWar.

If the example works for you, you should be able to make small changes to the project, e.g. change 480 in renderer.js to your own App ID, run other steamworks.js methods, etc.

If it doesn't work for you, you could try building steamworks.js from scratch and then running the test electron project from inside the Git repo. Just npm install and then npm run build in the root, then cd test/electron and npm install and npm start. It's supposed to work.

@mkaemmerer
Copy link

Hi @dfabulich, I'm @chostett's collaborator -- thanks for pointing us in the right direction ! I was able to run the example project successfully, and include my own App ID.

Another big step forward is that I was able to successfully initialize steamworks.js in our project, but only when running in development mode. Unfortunately the error persists in the production build. Made note of some notable differences in our project compared to the example, perhaps one of these is to blame:

  • build with electron-builder instead of electron-packager
  • using an older version of electron
  • initialize steamworks.js from the main process instead of the renderer process

I currently suspect the issue lies with electron-builder. I'll try to keep this thread up-to-date in case anyone else is experiencing the same issue.

@mkaemmerer
Copy link

Update: ran some experiments, and yep... it looks like an electron-builder issue. I could successfully build and run the example after moving the init to the main process, and after downgrading electron. On the other hand, the example crashes when I build it using electron-builder.

Minimal repro -- use the code in the example directory, change the package.json to this:

{
  "name": "steamworks.js-electron-test",
  "author": "(author and version fields required for electron-builder)",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "steamworks.js": "^0.3.0"
  },
  "devDependencies": {
    "electron": "24.2.0",
    "electron-builder": "24.6.3"
  },
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "pack": "electron-builder --dir",
    "dist": "electron-builder -m"
  },
  "build": {
    "mac": {
      "target": "zip"
    }
  }
}

Result is that the application crashes with a segfault immediately on launch, then OS X pops up an error-reporting modal "steamworks.js-electron-test quit unexpectedly."

@dfabulich
Copy link
Contributor

Why are you initializing steamworks from the main process? Steamworks wants access to the UI, so initializing in the renderer is probably best, following the example project.

@mkaemmerer
Copy link

@dfabulich - my project is using "contextIsolation" from the browser window, so I handle the calls to steamworks using IPC. I wanted to check to find out whether that makes a difference (in terms of whether or not the application crashes).

Turns out it doesn't. Whether steamworks is called from "main" or from "renderer" -- either way, the example crashes if I build it with electron-builder instead of electron-packager.

@dfabulich
Copy link
Contributor

dfabulich commented Aug 1, 2023

I use electron-builder myself. I run it like this:

electron-builder --x64 --win dir --linux dir --mac dir

I just tried it with electron-builder 24.6.3, electron 25.3.2, and initializing steamworks in the renderer. Didn't crash for me.

@mkaemmerer
Copy link

I still haven't found a compatible combination of versions and invocations. The latest thing I've tried is:

  • electron 25.3.2
  • electron-builder 24.6.3
  • steamworks.js 0.3.0

Using the code from the example app. Build with this command:

electron-builder --x64 --mac dir

The resulting .app bundle does not segfault, but it doesn't render HTML or connect to Steam either. The application window shows a blank page with no text in it.

@dfabulich
Copy link
Contributor

Does it render HTML when you rip out Steamworks?

@mkaemmerer
Copy link

If I remove steamworks completely then yes, the application renders as expected.

There are two points in the example code that call require('steamworks.js').

  • (A) the main process, which calls steamworks.electronEnableSteamOverlay()
  • (B) the renderer script, which callssteamworks.init(...), client.localplayer.getName(), client.overlay.activateToWebPage(...)

I ran a couple other experiments. Here were the results I got:

  • remove A and B --> app renders html
  • remove only A --> app does not render html
  • remove only B --> app renders html

I suspect the issue lies in the init call, but there's no logging in the example app and I haven't added any yet, so I can't say for sure.

@dfabulich
Copy link
Contributor

Are you calling activateToWebPage() on load? That can't be right. Try getting rid of that? (The Steam overlay is very finicky.)

@mkaemmerer
Copy link

Are you calling activateToWebPage() on load? That can't be right. Try getting rid of that? (The Steam overlay is very finicky.)

No, I never call it on load. It's called in the button event handler

@mkaemmerer
Copy link

Summary/status-update:

I can get steamworks.js to run correctly in development mode in my own project, but not when building it into a ".app" package. I can get steamworks.js to build and run as a ".app" using the example project. The primary difference seems to be the way the projects are built. I did some tests to try to build the example project using other build tools. I was unsuccessful.

  • electron-packager ✅
  • electron-builder ❌
  • electron forge 1

I don't particularly want to migrate my project to use electron-packager, but I'm not seeing a lot of other options at the moment.


1 In addition to my own tests, I found an issue about it in the electron forge repo -- electron/forge#3193

@dfabulich
Copy link
Contributor

One of the hardest things about steamworks.js is that sometimes people write in, saying, "it doesn't work on my machine," without providing detailed steps to allow others to reproduce their work. For example, in this case, you sent us package.json and a written description of your main/renderer, instead of a repository that demonstrates the error.

Your electron-builder package.json works great on my machine, using main.js, renderer.js, and index.html from the test/electron folder. I've filed a PR #115 to add an electron-builder sample to this repository; not sure how @ceifa will feel about it.

When I check out that branch, build steamworks.js, and npm run start in the electron-builder directory, it works, and shows my Steam user name. When i npm run dist, it generates an app in dist/mac-arm64. When I double-click it, it opens, and shows my Steam user name.

Does my electron-builder sample work on your machine? I've shipped dozens of Steam apps using steamworks.js using electron-builder. I'm certain in works.

If you'd like to make a similar PR for electron-forge, I can try that on my machine, too. (I've never used Forge, though.)

@mkaemmerer
Copy link

mkaemmerer commented Aug 9, 2023

@dfabulich - thank you for the reproducible example!

Unfortunately, the problem persists. Here are the steps I followed.

  1. Clone the repo - https://github.com/dfabulich/steamworks.js.git
  2. Check out the electron-builder branch
  3. cd ./test/electron-builder
  4. Install dependencies with npm install

First attempt

  • run npm start
    • ❌ error "Can't find dist/osx/steamworksjs.darwin-x64.node". Oh I see, I have to build the rust package first because the dist/ directory isn't part of the source code... trying again.
  • run npm install and npm build from project root.

Second attempt

  • npm start
    • ✅ app launches and connects to steam.
  • npm run dist
    • generates an app in dist/mac (NOT dist/mac-arm64 -- I'm building on a 2017 Intel i5 Macbook)
    • ❌ no errors, but the app launches to a blank screen. HTML does not load.

@mkaemmerer
Copy link

UPDATE:

Third attempt: explicitly disable code-signing in electron-builder

  • npm run dist -- -c.mac.identity=null
    • generates an app in dist/mac
    • ✅ app launches and shows steam username

By default, electron-builder was code-signing using my keychain. From https://www.electron.build/code-signing.html

On a macOS development machine, a valid and appropriate identity from your keychain will be automatically used.

This feels like huge progress, but still leaves the open question: "How do I use steamworks.js if I want to ship a signed, notarized mac app?"

@dfabulich
Copy link
Contributor

dfabulich commented Aug 9, 2023

Notarization works fine on ARM64, but fails on x86_64. See #103 and #114.

@ceifa
Copy link
Owner

ceifa commented Sep 2, 2023

@mkaemmerer can you check if the error still persists on latest version?

@x1911
Copy link

x1911 commented Apr 2, 2024

electron-builder --mac -c.mac.identity=null

this one works for me, but it shows error after uploaded to steam

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

No branches or pull requests

5 participants