Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.NullReferenceException in UnsafeNativeMethods.OnCallback #31

Open
christopherdude opened this issue Sep 15, 2021 · 4 comments
Open

Comments

@christopherdude
Copy link

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.

@JosePineiro
Copy link
Owner

JosePineiro commented Sep 18, 2021

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

@rainerllera
Copy link

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

@JosePineiro
Copy link
Owner

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);

@rainerllera
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants