Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from wee_alloc to default memory allocator, fix memory leak #4

Merged
merged 1 commit into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 2 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ crate-type = ["cdylib"]
wasm-bindgen = "0.2"
mikktspace = "0.2"
nalgebra = "0.19.0"
wee_alloc = "0.4.5"
# Debug only.
console_error_panic_hook = { version = "0.1" }

Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ extern crate console_error_panic_hook;
#[cfg(debug_assertions)]
use std::panic;

#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

/******************************************************************************
* JavaScript interface.
*/
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ tape('generateTangents', async (t) => {
t.end();
});

tape('generateTangents | memory', async (t) => {
const io = new NodeIO();
const doc = await io.read(path.resolve(__dirname, './cube.glb')).transform(unweld());
const cube = doc.getRoot().listMeshes()[0].listPrimitives()[0];

let initialMemory = -1;

for (let i = 0; i < 1000; i++) {
const tangentArray = mikktspace.generateTangents(
cube.getAttribute('POSITION').getArray(),
cube.getAttribute('NORMAL').getArray(),
cube.getAttribute('TEXCOORD_0').getArray(),
);

const currentMemory = mikktspace.__wasm.memory.buffer.byteLength / 1024 / 1024;
if (i === 0) {
initialMemory = currentMemory;
} else if ((i % 100) === 0) {
t.equals(currentMemory, initialMemory, `memory = ${initialMemory} MB @ ${i}/1000`);
}
}
t.end();
});

tape('generateTangents | error handling', (t) => {
const positions = new Float32Array();
const normals = new Float32Array();
Expand Down