Giter Club home page Giter Club logo

Comments (10)

Ono-Sendai avatar Ono-Sendai commented on June 23, 2024 1

Yes that is how I am working around it and how I worked out that this is likely the issue.
Please feel free to close the issue if you want, as this seems to be another emscripten / wasm bug.

from joltphysics.

Ono-Sendai avatar Ono-Sendai commented on June 23, 2024

Ok I guess this is what is happening: (from https://en.cppreference.com/w/cpp/thread/condition_variable/wait)

If these functions fail to meet the postconditions (lock.owns_lock()==true and lock.mutex() is locked by the calling thread), std::terminate is called. For example, this could happen if relocking the mutex throws an exception.

But of course in the Jolt code the lock is acquired immediately above the wait code, so I'm not sure what is going wrong.

std::unique_lock lock(mLock); mCount -= (int)inNumber; mWaitVariable.wait(lock, [this]() { return mCount >= 0; });

from joltphysics.

jrouwe avatar jrouwe commented on June 23, 2024

Hello,

I've not seen this crash before and it also doesn't make sense to me for the same reasons you mention. I'm guessing that it is not happening in the native version of your app or you would have created an issue sooner.

You could try commenting out the #ifdef JPH_PLATFORM_WINDOWS bits in the Semaphore class to make your Windows native app run the same code and check if you can repro the crash that way?

In any case I don't see any bugs mentioned in the emscripten issue trackers.

Maybe you can try another browser like Firefox (not Safari because that has issues with multithreading)?

from joltphysics.

Ono-Sendai avatar Ono-Sendai commented on June 23, 2024

Yeah it's just happening in Chrome currently.
Firefox fails for other reasons (hitting 2 GB mem usage with opengl calls fails), but seems to execute this code ok.

Do you have any more info about the Safari multithreading issues?

will try the JPH_PLATFORM_WINDOWS semaphore change on native.

from joltphysics.

Ono-Sendai avatar Ono-Sendai commented on June 23, 2024

Using condition_variable mWaitVariable on native Windows works fine (as expected).

from joltphysics.

jrouwe avatar jrouwe commented on June 23, 2024

Do you have any more info about the Safari multithreading issues?

See for example jrouwe/JoltPhysics.js#110 and #577

Luckily the issue seems to have been fixed in a recent development build of Safari.

Using condition_variable mWaitVariable on native Windows works fine (as expected).

A workaround that we could try is to make Linux/WASM use pthreads semaphores. Maybe those will work (at least they won't call std::terminate).

from joltphysics.

Ono-Sendai avatar Ono-Sendai commented on June 23, 2024

I'm hitting similar crashes in my non-Jolt code. So I even if I run Jolt with the single-threaded task manager, I still need to solve the issue. I think it's most likely miscompilation or misexecution of atomic variables, resulting in double-frees of reference-counted objects.

from joltphysics.

jrouwe avatar jrouwe commented on June 23, 2024

If you figure out what it is then I'd be curious to hear about it.

from joltphysics.

Ono-Sendai avatar Ono-Sendai commented on June 23, 2024

I have narrowed it down a little. Seems to be a combination of memory growth and atomics. Something like when the total amount of mem allocated to the WASM program (which I think takes the form of a single large buffer) increases, some atomic variable is accessed or changed incorrectly, leading to the 'crash'.

from joltphysics.

jrouwe avatar jrouwe commented on June 23, 2024

That makes sense, reallocation and atomics don't go together very well. But then you should be able to work around it by disabling memory growth -s ALLOW_MEMORY_GROWTH=0 and making sure that the initial memory block is large enough -s TOTAL_MEMORY=XXX (both parameters for emcc).

from joltphysics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.