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

emscripten example broken: missing API functions in emscripten's glfw3 #6240

Closed
Simon-L opened this issue Mar 13, 2023 · 7 comments
Closed
Labels

Comments

@Simon-L
Copy link

Simon-L commented Mar 13, 2023

Version/Branch of Dear ImGui:

Version: Fresh clone from github
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_wgpu.cpp
Operating System: Linux (Debian testing)

My Issue/Question:

Related to: https://github.com/ocornut/imgui/tree/master/examples/example_emscripten_wgpu
At least on my machine the example for emscripten is broken. First time using emscripten here, I followed the example's readme, installed recommended emscripten and ran the source command for the correct env vars etc.

make
...
wasm-ld: error: imgui_impl_glfw.o: undefined symbol: glfwGetError
wasm-ld: error: imgui_impl_glfw.o: undefined symbol: glfwGetGamepadState

It seems commits (here and here ) to the glfw impl without #ifdef guarding for emscripten cause this error as emscripten ships a special glfw that misses these functions.

Simply commenting these calls (3 lines total) in imgui_impl_glfw.cpp fixes the issue.

Am I missing something? As even recently emscripten was mentioned in the commit history and the glfwGetGamepadState call was added one year ago.

@ocornut
Copy link
Owner

ocornut commented Mar 13, 2023

It did indeed start breaking on CI a few days machines with Emscripten, but when I tried locally with latest I didn’t repro the issue.

It seems odd to me that the Gamepad function would get removed, although perhaps it never worked (i don’t remember testing gamepad on glfw + Emscripten).

Would ideally need to investigate recent Emscripten history.

@Simon-L
Copy link
Author

Simon-L commented Mar 13, 2023

Hello and thank you for your quick reply!

Did you do your local test with a fresh emscripten as well? I'm on 3.1.33
Could it be slight discrepancies for linux and other platforms emcc builds?

I forgot to mention that I also had to add ImGuiIO& io = ImGui::GetIO(); before this line or else io was just missing altogether. New API too iirc?

I should also add that even though it compiled I couldn't run it in the end in any browser as wgpu, as the Readme says, is very experimental. I had success with this other example that uses emscripten but not webgpu (Uh!), I guess just straight webgl? : https://github.com/jnmaloney/WebGui/blob/master/Makefile#L6-L10
For this to run, the calls in impl_glfw (see first post) must be commented out as well.

@ocornut
Copy link
Owner

ocornut commented Mar 13, 2023

Did you do your local test with a fresh emscripten as well? I'm on 3.1.33
Could it be slight discrepancies for linux and other platforms emcc builds?

I did update to 3.1.33 yes.
I don't know the reason yes! Going to try Emscripten on my WSL setup.

I forgot to mention that I also had to add ImGuiIO& io = ImGui::GetIO(); before this line or else io was just missing altogether. New API too iirc?

That's due to a small change I applied to all example on Friday and the local variable was missing from this example, my bad.

Both example_glfw_opengl3/ and example_sdl2_opengl3/ are designed to compile with Emscripten if you want to try them.

@Simon-L
Copy link
Author

Simon-L commented Mar 13, 2023

Both example_glfw_opengl3/ and example_sdl2_opengl3/ are designed to compile with Emscripten if you want to try them.

I actually just realised that, thank you for mentioning it! I guess it comes down to me being completely new to emscripten and ignoring some of the details... and not reading EXAMPLES.md which mentions these examples support emscripten, oops sorry... my bad on this!
I had to do the same commenting out of glfwGetError and glfwGetGamepadState to compile.

@ocornut ocornut added the web label Mar 13, 2023
@Simon-L
Copy link
Author

Simon-L commented Mar 13, 2023

Looking at this some more, one of the call is actually correctly guarded with an #if: https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_glfw.cpp#L315-L327
I don't know if it was made on purpose or for other incompatible things in the block

I put everything together in a new repo, it will evolve into my own usecase (some sort of viewer for DSP development) but as of this commit, except for the name and implot, it's pretty much the same as the example https://github.com/Simon-L/303freqgui/tree/951729ec3310664b6a8898b9065361522604140f

Should I update this issue's title?
Most sincere merci for your work and dedication from a fellow parisian programmer!

@ocornut
Copy link
Owner

ocornut commented Mar 13, 2023

Issue title is ok, but we need to investigate what changed in Emscripten because it might be a bug there

On Feb 25 they did update their emulation layer to GLFW 3.3 API:
https://github.com/emscripten-core/emscripten/commits/main/src/library_glfw.js

@ocornut
Copy link
Owner

ocornut commented Mar 14, 2023

Confirmed a few things now:

  • Link error repros on WSL, doesn't on Windows.
  • Emscripten updated their GLFW emulation layer to GLFW 3.3 but their support is incomplete. Those two functions are not available.
  • Our backends used those functions from 3.3 hence started failing recently.

Fixed with e39c255.

I noticed that Gamepad doesn't work correctly on GLFW+Emscripten (vs it works on SDL+Emscripten) because without glfwGetGamepadState() mapping are not standardized anyway. Probably we should hook and use Emscripten-level API instead of relying on GLFW JS emulation, similarly to #6096.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants