Skip to content

Commit

Permalink
Ensure renderers are disposed properly. Fixes issues when changing to…
Browse files Browse the repository at this point in the history
… initial state where chat bubbles and entity name labels would persist
  • Loading branch information
ethanmoffat committed Sep 14, 2022
1 parent c4c756c commit 967f279
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions EndlessClient/Rendering/Character/CharacterRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,14 @@ protected override void Dispose(bool disposing)
if (disposing)
{
_outline?.Dispose();

if (Game != null && Game.Components != null && Game.Components.Contains(_nameLabel))
Game.Components.Remove(_nameLabel);
_nameLabel?.Dispose();

if (_chatBubble.IsValueCreated)
_chatBubble.Value?.Dispose();

_sb?.Dispose();
_charRenderTarget?.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Xna.Framework;
using Optional;
using Optional.Collections;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -176,9 +177,14 @@ private ICharacterRenderer InitializeRendererForCharacter(EOLib.Domain.Character
renderer.Initialize();
return renderer;
}

public void Dispose()
{
_characterRendererRepository.Dispose();
}
}

public interface ICharacterRendererUpdater
public interface ICharacterRendererUpdater : IDisposable
{
void UpdateCharacters(GameTime gameTime);
}
Expand Down
3 changes: 3 additions & 0 deletions EndlessClient/Rendering/Map/MapRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ protected override void Dispose(bool disposing)
_mapObjectTarget.Dispose();
_sb.Dispose();
_mouseCursorRenderer.Dispose();

_npcRendererUpdater.Dispose();
_characterRendererUpdater.Dispose();
}

base.Dispose(disposing);
Expand Down
10 changes: 8 additions & 2 deletions EndlessClient/Rendering/NPC/NPCRendererUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using AutomaticTypeMapper;
using EOLib;
using EOLib.Domain.Map;
Expand Down Expand Up @@ -95,9 +96,14 @@ private void UpdateNPCRenderers(GameTime gameTime)
foreach (var renderer in _npcRendererRepository.NPCRenderers.Values)
renderer.Update(gameTime);
}

public void Dispose()
{
_npcRendererRepository.Dispose();
}
}

public interface INPCRendererUpdater
public interface INPCRendererUpdater : IDisposable
{
void UpdateNPCs(GameTime gameTime);
}
Expand Down

0 comments on commit 967f279

Please sign in to comment.