Skip to content
Snippets Groups Projects
Commit a3a76547 authored by rhdjw's avatar rhdjw
Browse files

Fixed potential CallbackOnCollectedDelegate exception.

parent c0a89b80
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,8 @@ namespace Kiss
/// </summary>
public class Network: System.IDisposable
{
private readonly Kiss.Capi.resultDlg resultCallback;
public delegate void ResultDlg(float[] result, Network network);
private struct Flight
......@@ -52,8 +54,12 @@ public class Network: System.IDisposable
/// </exception>
public Network(string path, bool verbose = false)
{
// Keep the callback in a class variable to prevent the garbage collector from collecting it
// which would cause a CallbackOnCollectedDelegate exception.
this.resultCallback = this.CResultCb;
Utils.CheckEnvThrow();
byte ret = Capi.kiss_load_network_prealloc(ref net, Capi.StringToPlatformBytes(path), CResultCb, Convert.ToByte(verbose));
byte ret = Capi.kiss_load_network_prealloc(ref net, Capi.StringToPlatformBytes(path), this.resultCallback, Convert.ToByte(verbose));
Console.WriteLine("ret: {0:D}", ret);
if(ret == 0)
throw new System.IO.FileLoadException(getError());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment