Skip to content

Commit

Permalink
Merge pull request #157 from wwwMADwww/HandlersFix156
Browse files Browse the repository at this point in the history
Fix #156
  • Loading branch information
smasherprog authored Aug 14, 2023
2 parents db80989 + ab7a7a1 commit 8250546
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src_csharp/MonitorCaptureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public class MonitorCaptureConfiguration : IDisposable
private bool disposedValue = false;
private static int MonitorSizeHint = 8;

private static MonitorWindowCallbackWithContext _onCaptureWithContext = OnCapture;
private static ScreenCaptureCallbackWithContext _onNewFrameWithContext = OnNewFrame;
private static ScreenCaptureCallbackWithContext _onFrameChangedWithContext = OnFrameChanged;
private static MouseCaptureCallbackWithContext _onMouseChangedWithContext = OnMouseChanged;

private static readonly UnmanagedHandles<MonitorCaptureConfiguration> UnmanagedHandles = new();

public static Monitor[] GetMonitors()
Expand Down Expand Up @@ -72,7 +77,7 @@ public MonitorCaptureConfiguration(MonitorCallback callback)
{
_monitorCallback = callback;
UnmanagedHandles.Add(this, out _handle);
Config = NativeFunctions.SCL_CreateMonitorCaptureConfigurationWithContext(OnCapture, _handle);
Config = NativeFunctions.SCL_CreateMonitorCaptureConfigurationWithContext(_onCaptureWithContext, _handle);
}
catch
{
Expand All @@ -87,7 +92,7 @@ public MonitorCaptureConfiguration OnNewFrame(Action<Image, Monitor> onNewFrame)
if (_onNewFrame == null)
{
_onNewFrame = onNewFrame;
NativeFunctions.SCL_MonitorOnNewFrameWithContext(Config, OnNewFrame);
NativeFunctions.SCL_MonitorOnNewFrameWithContext(Config, _onNewFrameWithContext);
}
else
{
Expand All @@ -104,7 +109,7 @@ public MonitorCaptureConfiguration OnFrameChanged(Action<Image, Monitor> onFrame
if (_onFrameChanged == null)
{
_onFrameChanged = onFrameChanged;
NativeFunctions.SCL_MonitorOnFrameChangedWithContext(Config, OnFrameChanged);
NativeFunctions.SCL_MonitorOnFrameChangedWithContext(Config, _onFrameChangedWithContext);
}
else
{
Expand All @@ -121,7 +126,7 @@ public MonitorCaptureConfiguration OnMouseChanged(Action<Image, MousePoint> onMo
if (_onMouseChanged == null)
{
_onMouseChanged = onMouseChanged;
NativeFunctions.SCL_MonitorOnMouseChangedWithContext(Config, OnMouseChanged);
NativeFunctions.SCL_MonitorOnMouseChangedWithContext(Config, _onMouseChangedWithContext);
}
else
{
Expand Down
13 changes: 9 additions & 4 deletions src_csharp/WindowCaptureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class WindowCaptureConfiguration : IDisposable

private static readonly UnmanagedHandles<WindowCaptureConfiguration> UnmanagedHandles = new();

private static MonitorWindowCallbackWithContext _onCaptureWithContext = OnCapture;
private static WindowCaptureCallbackWithContext _onNewFrameWithContext = OnNewFrame;
private static WindowCaptureCallbackWithContext _onFrameChangedWithContext = OnFrameChanged;
private static MouseCaptureCallbackWithContext _onMouseChangedWithContext = OnMouseChanged;

public static Window[] GetWindows()
{
return Utility.CopyUnmanagedWithHint<Window>(ref WindowSizeHint, NativeFunctions.SCL_GetWindows);
Expand Down Expand Up @@ -73,7 +78,7 @@ public WindowCaptureConfiguration(WindowCallback callback)
{
_windowCallback = callback;
UnmanagedHandles.Add(this, out _handle);
Config = NativeFunctions.SCL_CreateWindowCaptureConfigurationWithContext(OnCapture, _handle);
Config = NativeFunctions.SCL_CreateWindowCaptureConfigurationWithContext(_onCaptureWithContext, _handle);
}
catch
{
Expand All @@ -88,7 +93,7 @@ public WindowCaptureConfiguration OnNewFrame(Action<Image, Window> onNewFrame)
if (_onNewFrame == null)
{
_onNewFrame = onNewFrame;
NativeFunctions.SCL_WindowOnNewFrameWithContext(Config, OnNewFrame);
NativeFunctions.SCL_WindowOnNewFrameWithContext(Config, _onNewFrameWithContext);
}
else
{
Expand All @@ -105,7 +110,7 @@ public WindowCaptureConfiguration OnFrameChanged(Action<Image, Window> onFrameCh
if (_onFrameChanged == null)
{
_onFrameChanged = onFrameChanged;
NativeFunctions.SCL_WindowOnFrameChangedWithContext(Config, OnFrameChanged);
NativeFunctions.SCL_WindowOnFrameChangedWithContext(Config, _onFrameChangedWithContext);
}
else
{
Expand All @@ -122,7 +127,7 @@ public WindowCaptureConfiguration OnMouseChanged(Action<Image, MousePoint> onMou
if (_onMouseChanged == null)
{
_onMouseChanged = onMouseChanged;
NativeFunctions.SCL_WindowOnMouseChangedWithContext(Config, OnMouseChanged);
NativeFunctions.SCL_WindowOnMouseChangedWithContext(Config, _onMouseChangedWithContext);
}
else
{
Expand Down

0 comments on commit 8250546

Please sign in to comment.