From cb1101996bee3960cb7980792494efed13b8477f Mon Sep 17 00:00:00 2001 From: Marak Date: Tue, 12 Mar 2024 16:28:59 -0400 Subject: [PATCH] `MatterPhysics` - Ensures body map is removed `TensorFlow` - Set wasm to public root by default `Entity` - Adds try/catch around remote event inflate --- mantra-game/plugins/entity/lib/inflateEntity.js | 9 +++++++-- mantra-game/plugins/physics-matter/MatterPhysics.js | 2 +- mantra-game/plugins/tensorflow/TensorFlow.js | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mantra-game/plugins/entity/lib/inflateEntity.js b/mantra-game/plugins/entity/lib/inflateEntity.js index 9cce3e69..bee151ef 100644 --- a/mantra-game/plugins/entity/lib/inflateEntity.js +++ b/mantra-game/plugins/entity/lib/inflateEntity.js @@ -93,9 +93,14 @@ function defaultBuild(game, entityData) { if (supportedSerializedEvents.includes(p)) { // this is a serialized function, create a new function from the string and assign it to the entity - //console.log('inflateEntity serialized function', entityData[p]); + // console.log('inflateEntity serialized function', entityData.type, entityData[p], entityData); // this is a function that had .toSTring() called on it, we need to re-create the function - entityData[p] = eval('(' + entityData[p] + ')'); + try { + // Remark: This try/catch is not gaurenteed to catch all eval() errors + entityData[p] = eval('(' + entityData[p] + ')'); + } catch (err) { + console.log('Failed to inflate serialized function', entityData.type, entityData[p], entityData, err) + } //console.log("after inflateENtity seralize fn", entityData[p]) } diff --git a/mantra-game/plugins/physics-matter/MatterPhysics.js b/mantra-game/plugins/physics-matter/MatterPhysics.js index 330bb991..7744b662 100644 --- a/mantra-game/plugins/physics-matter/MatterPhysics.js +++ b/mantra-game/plugins/physics-matter/MatterPhysics.js @@ -226,7 +226,7 @@ class MatterPhysics extends PhysicsInterface { let body = this.bodyMap[entityId]; if (body) { Matter.World.remove(this.engine.world, body); - delete this.bodyMap[body.myEntityId]; + delete this.bodyMap[body.myEntityId.toString()]; } } diff --git a/mantra-game/plugins/tensorflow/TensorFlow.js b/mantra-game/plugins/tensorflow/TensorFlow.js index a092d137..af61dd1c 100644 --- a/mantra-game/plugins/tensorflow/TensorFlow.js +++ b/mantra-game/plugins/tensorflow/TensorFlow.js @@ -33,7 +33,7 @@ export default class TensorFlow { // await this.loadModel(); - + setWasmPaths('/'); this.game.systemsManager.addSystem('tensorflow', this); } @@ -161,6 +161,7 @@ export default class TensorFlow { // Apply actions based on the generated random actions Object.keys(actions).forEach(action => { if (actions[action]) { + // console.log('applying action', action, player) this.game.rules.emit(action, player); } });