blish-hud/Blish-HUD

Module SettingsView.Unload() not called when switching between Module Settings tab and other tabs of the blish settings window

Taschenbuch opened this issue · 0 comments

occurs in Blish 1.1.1

observed behavior

View.Unload() method is never called on the custom settings view created by overriding Module.GetSettingsView() when switching between the Module Settings tab and other tabs of the blish settings window. As a consequence when in View.Build() an event is subscribed to, it cannot be unsubscribed in View.Unload(). This leads to an additional event subscription each time the module settings tab is selected.

Example:

Module class

public override IView GetSettingsView()
{
    return new ModuleSettingsView(_service);
}

ModuleSettingsView class

public class ModuleSettingsView : View
{
    public ModuleSettingsView(Service service)
    {
        _service = service;
    }

    protected override async void Build(Container buildPanel) // called each time the module settings tab is opened
    {
        _service.MyEvent += OnMyEvent;
    }

    protected override void Unload() // never called
    {
        _service.MyEvent -= OnMyEvent;
    }
}

expected behavior

View.Unload() is called when

  • the module settings tab is left by switching to another tab of blish settings window
  • the blish settings window is closed
  • "Disable Module" is clicked

workaround until fixed

Module class

private ModuleSettingsView _moduleSettingsView;

public override IView GetSettingsView()
{
    _moduleSettingsView ??= new ModuleSettingsView(_service); 
    return _moduleSettingsView;
}

ModuleSettingsView class

public class ModuleSettingsView : View
{
    public ModuleSettingsView(Service service)
    {
        _service = service;
    }

    protected override async void Build(Container buildPanel) // called each time the module settings tab is opened
    {
        _service.MyEvent -= OnMyEvent;
        _service.MyEvent += OnMyEvent;
    }
}

relevant discord discussion:

https://discord.com/channels/531175899588984842/599270434642460753/1227691731231838360