🆙 Updates

- Added Test Coverage
- Fix Potential Memory Leaks
This commit is contained in:
DuckieTM
2026-01-31 13:21:59 +01:00
parent e263ce59bf
commit eb4fe80612
18 changed files with 1689 additions and 110 deletions
@@ -15,6 +15,7 @@ export class AvatarAssetDownloadManager
private _incompleteFigures: Map<string, AvatarAssetDownloadLibrary[]> = new Map();
private _currentDownloads: AvatarAssetDownloadLibrary[] = [];
private _libraryNames: string[] = [];
private _libraryLoadedCallback: (event: AvatarRenderLibraryEvent) => void = null;
constructor(assets: IAssetManager, structure: AvatarStructure)
{
@@ -38,11 +39,27 @@ export class AvatarAssetDownloadManager
this.processFigureMap(responseData.libraries);
GetEventDispatcher().addEventListener(NitroEventType.AVATAR_ASSET_DOWNLOADED, (event: AvatarRenderLibraryEvent) => this.onLibraryLoaded(event));
// Store callback for cleanup
this._libraryLoadedCallback = (event: AvatarRenderLibraryEvent) => this.onLibraryLoaded(event);
GetEventDispatcher().addEventListener(NitroEventType.AVATAR_ASSET_DOWNLOADED, this._libraryLoadedCallback);
await this.processMissingLibraries();
}
public dispose(): void
{
if(this._libraryLoadedCallback)
{
GetEventDispatcher().removeEventListener(NitroEventType.AVATAR_ASSET_DOWNLOADED, this._libraryLoadedCallback);
this._libraryLoadedCallback = null;
}
this._figureMap.clear();
this._figureListeners.clear();
this._incompleteFigures.clear();
this._currentDownloads = [];
}
private processFigureMap(data: any): void
{
if(!data) return;
+20 -2
View File
@@ -24,6 +24,7 @@ export class AvatarRenderManager implements IAvatarRenderManager
private _effectAssetDownloadManager: EffectAssetDownloadManager = new EffectAssetDownloadManager(GetAssetManager(), this._structure);
private _placeHolderFigure: AvatarFigureContainer = new AvatarFigureContainer(AvatarRenderManager.DEFAULT_FIGURE);
private _aliasResetCallback: () => void = null;
public async init(): Promise<void>
{
@@ -37,13 +38,30 @@ export class AvatarRenderManager implements IAvatarRenderManager
this._aliasCollection.init();
GetEventDispatcher().addEventListener(NitroEventType.AVATAR_ASSET_LOADED, () => this._aliasCollection.reset());
GetEventDispatcher().addEventListener(NitroEventType.AVATAR_EFFECT_LOADED, () => this._aliasCollection.reset());
// Store callback for cleanup
this._aliasResetCallback = () => this._aliasCollection.reset();
GetEventDispatcher().addEventListener(NitroEventType.AVATAR_ASSET_LOADED, this._aliasResetCallback);
GetEventDispatcher().addEventListener(NitroEventType.AVATAR_EFFECT_LOADED, this._aliasResetCallback);
await this._avatarAssetDownloadManager.init();
await this._effectAssetDownloadManager.init();
}
public dispose(): void
{
// Remove event listeners
if(this._aliasResetCallback)
{
GetEventDispatcher().removeEventListener(NitroEventType.AVATAR_ASSET_LOADED, this._aliasResetCallback);
GetEventDispatcher().removeEventListener(NitroEventType.AVATAR_EFFECT_LOADED, this._aliasResetCallback);
this._aliasResetCallback = null;
}
// Dispose download managers
this._avatarAssetDownloadManager?.dispose();
this._effectAssetDownloadManager?.dispose();
}
private async loadActions(): Promise<void>
{
const defaultActions = GetConfiguration().getValue<string>('avatar.default.actions');
@@ -15,6 +15,7 @@ export class EffectAssetDownloadManager
private _incompleteEffects: Map<string, EffectAssetDownloadLibrary[]> = new Map();
private _currentDownloads: EffectAssetDownloadLibrary[] = [];
private _libraryNames: string[] = [];
private _libraryLoadedCallback: (event: AvatarRenderEffectLibraryEvent) => void = null;
constructor(assets: IAssetManager, structure: AvatarStructure)
{
@@ -38,11 +39,27 @@ export class EffectAssetDownloadManager
this.processEffectMap(responseData.effects);
GetEventDispatcher().addEventListener(NitroEventType.AVATAR_EFFECT_DOWNLOADED, (event: AvatarRenderEffectLibraryEvent) => this.onLibraryLoaded(event));
// Store callback for cleanup
this._libraryLoadedCallback = (event: AvatarRenderEffectLibraryEvent) => this.onLibraryLoaded(event);
GetEventDispatcher().addEventListener(NitroEventType.AVATAR_EFFECT_DOWNLOADED, this._libraryLoadedCallback);
await this.processMissingLibraries();
}
public dispose(): void
{
if(this._libraryLoadedCallback)
{
GetEventDispatcher().removeEventListener(NitroEventType.AVATAR_EFFECT_DOWNLOADED, this._libraryLoadedCallback);
this._libraryLoadedCallback = null;
}
this._effectMap.clear();
this._effectListeners.clear();
this._incompleteEffects.clear();
this._currentDownloads = [];
}
private processEffectMap(data: any): void
{
if(!data) return;