Skip to content

Commit

Permalink
Autogenned changes for freeing
Browse files Browse the repository at this point in the history
  • Loading branch information
zalo committed May 4, 2023
1 parent 5da0408 commit 4759515
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions dist/mujoco_wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ export enum mjtLRMode {
export interface Model {
new (filename : string) : Model;
load_from_xml(str: string): Model;
/** Free the memory associated with the model */
free(): void;
/** Retrive various parameters of the current simulation */
getOptions(): any;
// MODEL_INTERFACE
Expand Down Expand Up @@ -1413,12 +1415,16 @@ export interface Model {

export interface State {
new (model : Model) : State;
/** Free the memory associated with the state */
free(): void;
}

export interface Simulation {
new (model : Model, state : State) : Simulation;
state() : State;
model() : Model;
/** Free the memory associated with both the model and the state in the simulation */
free() : void;
/** Apply cartesian force and torque (outside xfrc_applied mechanism) */
applyForce(fx: number, fy: number, fz: number, tx: number, ty: number, tz: number, px: number, py: number, pz: number, body_id: number): void;

Expand Down
Binary file modified dist/mujoco_wasm.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/mujocoUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export async function loadSceneFromURL(mujoco, filename, parent) {
let model = parent.model;
let state = parent.state;
let simulation = parent.simulation;

// Decode the null-terminated string names.
let textDecoder = new TextDecoder("utf-8");
let fullString = textDecoder.decode(model.names);
Expand Down
6 changes: 5 additions & 1 deletion src/main.genned.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ class Simulation {

State *state() { return _state; }
Model *model() { return _model; }
void free() { mju_free(_state); mju_free(_model); }

void applyForce(
mjtNum fx, mjtNum fy, mjtNum fz,
Expand Down Expand Up @@ -951,6 +952,7 @@ EMSCRIPTEN_BINDINGS(mujoco_wasm) {
.class_function("load_from_xml", &Model::load_from_xml)
.class_function("load_from_mjb", &Model::load_from_mjb)
.function("ptr", &Model::ptr, allow_raw_pointers())
.function("free" , &Model::free )
.function("getVal" , &Model::getVal )
.function("getOptions" , &Model::getOptions )
// MJMODEL_BINDINGS
Expand Down Expand Up @@ -1305,14 +1307,16 @@ EMSCRIPTEN_BINDINGS(mujoco_wasm) {
class_<State>("State")
.constructor<Model>()
.function("ptr" , &State::ptr, allow_raw_pointers())
.function("free" , &State::free )
.function("getVal", &State::getVal);

class_<Simulation>("Simulation")
.constructor<Model *, State *>()
.function("state" , &Simulation::state, allow_raw_pointers())
.function("model" , &Simulation::model, allow_raw_pointers())
.function("free" , &Simulation::free )
.function("applyForce", &Simulation::applyForce)
.function("applyPose" , &Simulation::applyPose)
.function("applyPose" , &Simulation::applyPose )
// MJDATA_BINDINGS
.property("qpos" , &Simulation::qpos )
.property("qvel" , &Simulation::qvel )
Expand Down

0 comments on commit 4759515

Please sign in to comment.