Skip to content

Commit

Permalink
dispose resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Narazaka committed Jul 13, 2023
1 parent 6312a0d commit 3f46cb2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/nameplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ function handleNameplate(
nameplatePositionHeightOptions?: NameplatePositionHeightOptions,
nameplateTextureOptions?: NameplateTextureOptions,
) {
let exists = false;
const nameplate = getOrAddSprite(
getOrAddNameplateContainer(
parent,
avatarObject,
nameplatePositionHeightOptions,
),
"nameplate",
{
afterExists: () => {
exists = true;
},
},
);
const previousName = nameCache.get(id);
const useName = playerName(name);
Expand All @@ -82,6 +88,10 @@ function handleNameplate(
nameplate.id,
nameplateTextureOptions,
);
if (exists) {
nameplate.material.map?.dispose();
nameplate.material.dispose();
}
nameplate.material = material;
nameplate.scale.set(scale.x, scale.y, scale.z);
nameCache.set(id, useName);
Expand Down

0 comments on commit 3f46cb2

Please sign in to comment.