BJS seemingly causes an error in another library I'm using, by assigning/removing object properties (?)

Good day!

Not sure if this qualifies as a bug, but I didn’t know where else to post it other than potentially the GitHub issues page, which said to use the forums first :slight_smile:

I’m using BabylonJS in combination with another library in my app, which basically runs a Lua VM inside the JavaScript VM (I know that sounds insane). This is the one:

This has always worked fine, but when I last tried to update BJS it would suddenly kill the app while loading the scene with this rather cryptic stack trace:

uncaught exception Error: ownKeys unknown for fengari object
at Object.ownKeys (fengari-web.js:5218)
at assign (<anonymous>)
at __assign (tslib.es6.js:38)
at new Scene (scene.ts:1375)
at new (fengari-web.js:5104)
at Object.t [as luaD_precall] (fengari-web.js:2152)
at Object.t.exports.luaV_execute (fengari-web.js:4240)
at ut (fengari-web.js:2278)
at Object.ht [as luaD_callnoyield] (fengari-web.js:2426)
at Ot (fengari-web.js:5603)``

Now, clearly this is ultimately caused by fengari and not BJS, but bear with me for a second. While the error itself is thrown in lines 645 ll. of that library, it is clearly caused by Babylon as the other library hasn’t changed in ages, and it only starts occuring if I upgrade BJS.

I don’t quite understand what exactly is happening, but I’ve investigated via git checkout and binary search to notice the following:

Tag/Commit | Status
4.1.0-beta.12 OK
4.1.0-beta.13 OK
93e994c81d36125394348c263cc1b44d3e502450 OK
9ae2cd287346ee5317be284fe3129e5053010c78 OK
eea03c5c7e0e4929687f3a58de0be85f4bc1fc36 NOT OK
bd120a1a41602d653c35fbbbecac9c15ee19f844 NOT OK

If I’m not mistaken, this means that the issue only started appearing after 93e994c81d36125394348c263cc1b44d3e502450, and indeed there is the following code in said commit:

var fullOptions = Object tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])({
  useGeometryUniqueIdsMap: true,
  useMaterialMeshMap: true,
  useClonedMeshMap: true,
  virtual: false
},
options);

This is in line 172715 of babylon.max.js

Additional information:

  • The BJS scene is stored in a Proxy object representing a Lua table, referring to the actual JS object internally AFAICT
  • It seems that BJS is now modifying the object via Object.assign (or a custom __assign function), which alters its structure
  • I assume that the Lua framework then detects the invalid state, causing the error I described
  • fengari also uses webpack, though I don’t know if it’s relevant here

I hope you can shed some insight as to what’s happening here, or at least have some ideas as to what I should be looking for with the debugger.

Thanks for your time!

Hi,

From a quick search, it seems related to the way fengari deals with the ownKeys method - ownKeys metamethod should default to using lua_next · Issue #39 · fengari-lua/fengari-interop · GitHub
This probably started after upgrading the director version used to compile Babylon. I can recommend you compiling Babylon using an older version of TS or change the compilation target version, which would probably have an different version of assign . Or maybe try the es6 modules version? I honestly didn’t check it, but since the target is different, there might be a difference

Thanks! Is there any disadvantage (besides the inconvenience) to doing this? I’ve so far simply downloaded the version distributed at https://preview.babylonjs.com/babylon.js, which has always been working fine. Naturally, I don’t want to break things just to work around this particular problem.

Actually here the conflict would be with typescript and not babylon so any lib relying on typescript targetting es5 would have the same result. Maybe you could also chat with the owner of the other lib and let them know of the conflict ?