Forum Xamarin.iOS

Problem with CGPDFOperatorTable SetCallback method

Hi to all!

I'm trying to write search function for a pdf reader.
I try to translate this objecive-c code into c#:
http://web.archive.org/web/20131122162015/http://blog.random-ideas.net/?p=184

I have problem with SetCallback method. When I try to use the GCHandle.FromIntPtr method I get this error message and my app is crashed:
"Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application."

My callback action is so simply:

        table.SetCallback("Tj", (inScanner, userInfo) =>
        {
            if (inScanner == IntPtr.Zero || userInfo == IntPtr.Zero)
                return;

            GCHandle handle = GCHandle.FromIntPtr(inScanner);
            CGPDFScanner scan = handle.Target as CGPDFScanner;
            handle.Free();
        });

But it is strange, if I use the userInfo in the GCHandle.FromIntPtr method as a parameter, I get the correct CGPDFScanner object at the first time, but the second time app is crashed.

Could you push me in the right direction or give me some advice what do I wrong?

Thank you very much!

Tagged:
Sign In or Register to comment.