Skip to content

Commit

Permalink
Keep track of event callbacks in static field to avoid callbackOnColl…
Browse files Browse the repository at this point in the history
…ectedDelegate. Needs proper fix.
  • Loading branch information
mfkl committed Dec 14, 2017
1 parent 0134940 commit 2177497
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions LibVlcSharp/EventManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
using VideoLAN.LibVLC.Events;
Expand All @@ -7,7 +8,7 @@ namespace VideoLAN.LibVLC
{
public abstract class EventManager
{
public struct Internal
public struct Native
{
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl, EntryPoint = "libvlc_event_attach")]
Expand All @@ -21,6 +22,7 @@ internal static extern void LibVLCEventDetach(IntPtr eventManager, EventType eve
}

public IntPtr NativeReference;
static readonly List<EventCallback> Cb = new List<EventCallback>();

protected EventManager(IntPtr ptr)
{
Expand All @@ -32,13 +34,15 @@ protected EventManager(IntPtr ptr)

protected void AttachEvent(EventType eventType, EventCallback eventCallback)
{
if(Internal.LibVLCEventAttach(NativeReference, eventType, eventCallback, IntPtr.Zero) != 0)
if(Native.LibVLCEventAttach(NativeReference, eventType, eventCallback, IntPtr.Zero) != 0)
throw new VLCException($"Could not attach event {eventType}");
Cb.Add(eventCallback);
}

protected void DetachEvent(EventType eventType, EventCallback eventCallback)
{
Internal.LibVLCEventDetach(NativeReference, eventType, eventCallback, IntPtr.Zero);
Native.LibVLCEventDetach(NativeReference, eventType, eventCallback, IntPtr.Zero);
Cb.Remove(eventCallback);
}

protected LibVLCEvent RetrieveEvent(IntPtr eventPtr)
Expand Down

0 comments on commit 2177497

Please sign in to comment.