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

fix!: consume BeatmapAttributesBuilder on build #23

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

MaxOhn
Copy link
Owner

@MaxOhn MaxOhn commented Oct 15, 2024

Turns out #22 was only a band-aid for an underlying issue.

Passing a Beatmap to BeatmapAttributesBuilder would make the builder hold onto it even after build is called, meaning the map would still be marked as used. This is because build does not consume the builder to allow for re-use.

This PR makes build take ownership of the builder, causing future interactions with that same builder instance to fail with "null pointer passed to rust". Since ownership is taken, returning from build will drop self and all its fields, including the beatmap, causing it to no longer be marked as used.

Until a version containing this fix is released (which will be v2.0.0), there is an available workaround:

  • Creating a BeatmapAttributesBuilder and storing it in a variable
  • Calling .build() on that variable
  • Explicitly freeing the builder.
const builder = new rosu.BeatmapAttributesBuilder({
  map: my_beatmap,
  mods: my_mods,
});
const attributes = builder.build();
builder.free(); // <-

// now map can be free'd too
my_beatmap.free();

@MaxOhn MaxOhn merged commit e3c56ad into main Oct 15, 2024
5 checks passed
@MaxOhn MaxOhn deleted the consume-map-attr-builder branch October 15, 2024 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant