toolmanager: when electing to close and not restart a tool because of lack of services on the new core, clear out all services attached to the core first. this will turn some existing silent failures into NullReferenceExceptions, likely. fix one such bug in GBAGPUView

This commit is contained in:
goyuken 2014-12-31 17:18:51 +00:00
parent eacadc8e09
commit d1caf79a56
3 changed files with 22 additions and 1 deletions

View File

@ -794,7 +794,10 @@ namespace BizHawk.Client.EmuHawk
private void GBAGPUView_FormClosed(object sender, FormClosedEventArgs e)
{
gba.SetScanlineCallback(null, 0);
if (gba != null)
{
gba.SetScanlineCallback(null, 0);
}
}
#region copy to clipboard

View File

@ -358,6 +358,7 @@ namespace BizHawk.Client.EmuHawk
else
{
unavailable.Add(tool);
ServiceInjector.ClearServices(tool); // the services of the old emulator core are no longer valid on the tool
}
}

View File

@ -12,6 +12,23 @@ namespace BizHawk.Emulation.Common
/// </summary>
public static class ServiceInjector
{
/// <summary>
/// clears all services from a target
/// </summary>
/// <param name="target"></param>
public static void ClearServices(object target)
{
Type targetType = target.GetType();
object[] tmp = new object[1];
foreach (var propinfo in
targetType.GetPropertiesWithAttrib(typeof(RequiredService))
.Concat(targetType.GetPropertiesWithAttrib(typeof(OptionalService))))
{
propinfo.GetSetMethod(true).Invoke(target, tmp);
}
}
/// <summary>
/// Feeds the target its required services.
/// </summary>