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

doc: readme warning #15

Merged
merged 2 commits into from
Jul 10, 2024
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Class containing a parsed `.osu` file, ready to be passed to difficulty and perf
The constructor takes an object of type `Uint8Array | string` representing the content of a `.osu`
file and throws an error if decoding the beatmap fails.

⚠️WARNING⚠️

Due to [some current JavaScript oddities](https://github.com/rustwasm/wasm-bindgen/issues/3917), Wasm is not always able to track down objects' lifetime meaning it is possible that memory of unused instances might not get cleared automatically. Hence, to not risk leaking memory, it is recommended to free `Beatmap` instances manually when they're no longer needed with the `free(): void` method.

To convert a beatmap use the `convert(GameMode): void` method.

`Beatmap` provides various getters:
Expand Down Expand Up @@ -228,6 +232,9 @@ const currAttrs = new rosu.Performance({
}).calculate(maxAttrs); // Re-using previous attributes to speed up the calculation.

console.log(`PP: ${currAttrs.pp}/${maxAttrs.pp} | Stars: ${maxAttrs.difficulty.stars}`);

// Free the beatmap manually to avoid risking memory leakage.
map.free();
```

### Gradual calculation
Expand Down Expand Up @@ -274,6 +281,8 @@ while (gradualPerf.nRemaining > 0) {
console.log(`PP: ${gradualPerf.next(state)?.pp}`);
j += 1;
}

map.free();
```

## Installing rosu-pp-js
Expand Down
3 changes: 3 additions & 0 deletions rosu_pp_js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ export interface ScoreState {
/**
* All beatmap data that is relevant for difficulty and performance
* calculation.
*
* It is recommended to call the method `Beatmap.free` on instances that are
* no longer in use to avoid the risk of leaking memory.
*/
export class Beatmap {
free(): void;
Expand Down
3 changes: 3 additions & 0 deletions src/beatmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ use crate::{

/// All beatmap data that is relevant for difficulty and performance
/// calculation.
///
/// It is recommended to call the method `Beatmap.free` on instances that are
/// no longer in use to avoid the risk of leaking memory.
#[wasm_bindgen(js_name = Beatmap)]
pub struct JsBeatmap {
pub(crate) inner: Beatmap,
Expand Down