fabmax / physx-js-webidl

Javascript WASM bindings for Nvidia PhysX
MIT License
117 stars 27 forks source link

"Cannot read properties of undefined" using new enums #22

Closed JohnnyStreet closed 1 year ago

JohnnyStreet commented 1 year ago

I noticed more of the enums are exposed in recent updates. Everything compiles fine with the changes I made but, when referencing enums like PhysX.PxShapeFlagEnum.SCENE_QUERY_SHAPE for example, I get Cannot read properties of undefined (reading 'SCENE_QUERY_SHAPE')

fabmax commented 1 year ago

emscripten handles enums in a pretty awkward way: The values are not encapsulated in separate objects but exposed directly by their names (e.g. PhysX.eSCENE_QUERY_SHAPE). However, this way, values with the same name of different enums can collide and the values overwrite each other, so you should not use these.

The best way is to call the internal wrapper functions instead:

PhysX._emscripten_enum_PxShapeFlagEnum_eSCENE_QUERY_SHAPE();

I opened an issue regarding this a while ago but it never got fixed.

JohnnyStreet commented 1 year ago

Maybe it's because I am using typescript (with generated typescript definitions) but I don't have _emscripten_enum_NameSpaceA_EnumA_SomeValue() which is what I was using before, in a commonjs project that I got working some months back.

EDIT: My fault. This appears to happen when referencing it as an import before calling Physx(). Closing.