WebP-wrapper icon indicating copy to clipboard operation
WebP-wrapper copied to clipboard

System.NullReferenceException in UnsafeNativeMethods.OnCallback

Open christopherdude opened this issue 3 years ago • 4 comments

UnsafeNativeMethods.OnCallback = new UnsafeNativeMethods.WebPMemoryWrite(MyWriter); is causing an exception:

System.NullReferenceException Object reference not set to an instance of an object. at UnsafeNativeMethods.WebPEncode_x64(WebPConfig& config, WebPPicture& picture) at WebP.AdvancedEncode(Bitmap bmp, WebPConfig config, Boolean info)

I can only seem to reproduce this on a server; running in development mode works fine.

christopherdude avatar Sep 15 '21 22:09 christopherdude

I have updated the 64-bit library to version 1.2.1 Please try her. If you use the 32-bit version, I recommend you recompile this library. I have put instructions on how to do it in Compile dll.txt

JosePineiro avatar Sep 18 '21 21:09 JosePineiro

Any updates on this? getting the same error :) and updated library didn't fix it for me

rainerllera avatar Nov 08 '21 10:11 rainerllera

Please, test this change:

[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)] You should end up with:

[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false, ExactSpelling = true)] internal static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);

JosePineiro avatar Nov 28 '21 18:11 JosePineiro

Hey @JosePineiro , it was about a multi-threaded scenario for me, and the fact that OnCallback was static. The WebP class was being accessed/instantiated by multiple threads therefore OnCallback was being set null, and I was getting those NullReferenceExceptions. I made OnCallback an instance property and made sure to release it properly, it solved it for me. Thanks!

rainerllera avatar Nov 29 '21 06:11 rainerllera