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

Crashes iOS Safari and iOS Chrome #14

Open
canadaduane opened this issue Feb 28, 2021 · 10 comments
Open

Crashes iOS Safari and iOS Chrome #14

canadaduane opened this issue Feb 28, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@canadaduane
Copy link

canadaduane commented Feb 28, 2021

I notice that the rapier.rs 3d demo crashes iOS Safari (14.0.1) and iOS Chrome (87).

Unfortunately, it crashes the browser (no console logs, no crash traces), so it's difficult to say what's causing the problem.

The error message in Safari is "A problem repeatedly occurred on [url]". In Chrome the error message is "Can't open this page" with an "aww snap" crash icon ().

@cauthmann
Copy link

Can confirm this bug.

I've written a small rapier.rs/webgl app, a dice-throwing simulator for a webrtc video chat. Anytime someone threw dice, a certain person got disconnected. Turns out they were using safari, and something crashed and reloaded the page. They've since switched to firefox where it works fine.

I wrote the WebGL renderer from scratch, which means that I'm probably triggering different render paths than the rapier 3d demo, and other webgl apps work fine for them. Maybe a WASM bug in safari? I didn't debug further as I don't own any apple devices.

  "dependencies": {
    "@dimforge/rapier3d-compat": "^0.3.1",
    "gl-matrix": "^3.3.0"
  },

@sebcrozet
Copy link
Member

sebcrozet commented Apr 5, 2021

I started investigating the bug. The iOS crash appears to originate from a segfault on WebKit.
Right now, we optimize the Rapier WASM files using the wasm-opt options: -O4 --enable-mutable-globals. Removing --enable-mutable-globals appears to fix the problem.

I'm actually not sure why we have --enable-mutable-globals in the first place. I will take a closer look tomorrow. If we don't need it, I'll remove that option and make a new release that should work on safari iOS.

@sebcrozet sebcrozet added the bug Something isn't working label Apr 5, 2021
@sebcrozet
Copy link
Member

It looks like we needed --enabled-mutable-globals because of an issue in wasm-bindgen which has been fixed recently: rustwasm/wasm-bindgen#2391
So we can safely remove this flag now and make a working iOS version.

@sebcrozet
Copy link
Member

sebcrozet commented Apr 6, 2021

Interestingly, our WASM demos continue to crash on iOS when they are packaged by webpack. If I use webpack --debug then it works fine. I am not very experienced with webpack but I guess this problem isn't on our side? Does anyone already experienced a situation where the app works fine with webpack --debug but not webpack?

For the time being, I simply published our demos built using webpack --debug. I release Rapier 0.5.3 with the fix.

@canadaduane
Copy link
Author

canadaduane commented Apr 7, 2021

Cross-posting my comment from Discord here:

I can see that the demo is working on iPad, but I can't seem to get my app to build in such a way that it works. Even with the webpack --debug flag, I still get the iOS crash. Are you using webpack v4 or v5? (I'm on v4 still).

Also, reflecting a bit, I'm a bit uncertain as to why webpack --debug would fix anything, as my understanding is that it simply adds more logging information to console while compiling.

Update: the --debug flag is also no longer valid in webpack 5.

@cauthmann
Copy link

I updated to 0.5.3, using rapier3d-compat (thus there's no bundler touching the WASM), but my Safari using friend still gets kicked out the moment dice start rolling - but now they can see the dice for a split second before the tab crashes. Improvements I guess?

Sorry I cannot debug further.

@canadaduane
Copy link
Author

So in our case, an additional cause of trouble was our use of TerserPlugin to minify our javascript. It looks like Terser does something to the rapier3d glue code between our app and wasm--still uncertain what, exactly, it is doing to cause problems. But this narrows the problem sufficiently that we can at least get a production build working by excluding the dimforge/rapier3d chunk from Terser (it was always a chunk, anyway, because it must use a dynamic import). Here is how we configured webpack 4:

  // ... snip ...
  optimization: {
    /**
     * We need a separate chunk for @dimforge/rapier3d so that TerserPlugin can
     * exclude it from optimization, so that the physics engine wasm bundle will
     * work on iOS devices. See https://stackoverflow.com/a/58133835/159344.
     */
    splitChunks: {
      cacheGroups: {
        dimforge: {
          test: /[\\/]node_modules[\\/](@dimforge)[\\/]/,
          name: "dimforge",
          chunks: "all",
        },
      },
    },
    minimizer: [
      new TerserPlugin({
        // Exclude physics engine glue javascript (necessary for iOS devices)
        exclude: "dimforge",
      })
    ],
  }
// ...

@LeXXik
Copy link

LeXXik commented Apr 29, 2021

I can confirm. I use Rollup, instead of Webpack, though.
I just tried to run my test project on iOS 14.2 / Safari, and it crashes if Terser is used. I do not use rapier-compat, though, so there is no Wasm injected as string, only the Wasm glue file and the application code.

@canadaduane
Copy link
Author

@LeXXik Are you able to share your working Rollup configuration for wasm, specifically? I filed an issue that has since been closed as "stale" regarding my inability to get rapier3d working with rollup. Very curious to know how you got it working.

@LeXXik
Copy link

LeXXik commented Apr 30, 2021

@canadaduane I will reach you over Discord, to keep the issue on topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants