Access violation exception (0xC0000005) when trying to read from memory location 0x00000000

-1

I have an application (our application) Multi-threaded where sometimes crash, there is no exceptions (we have subscribe tu UnhandledException). We can have days or months between 2 crashes. All threads are create manually, we not use Threadpool.

I know is a problem with non managed memory but in my application we have none non-managed function (There non importdll), but we use a lib MIL (library for Image Processing) which use some IntPtr in our app.

I have dump of the crash but not always easy to find something

This is the result of the crash thread (from DebugDiag) :

Entry point   clr!:: 
Create time   16/11/2020 18:12:39 
Time spent in user mode   0 Days 00:03:55.515 
Time spent in kernel mode   0 Days 00:00:03.625 

Call Stack

clr!SVR::gc_heap::mark_object_simple+91    
clr!SVR::gc_heap::mark_through_cards_for_segments+482    
clr!SVR::gc_heap::mark_phase+302    
clr!SVR::gc_heap::gc1+b1    
clr!SVR::gc_heap::garbage_collect+f0    
clr!SVR::gc_heap::gc_thread_function+74    
clr!SVR::gc_heap::gc_thread_stub+9a    
clr!<lambda_984b1062d0d4b010966442b24889003f>::<lambda_invoker_cdecl>+51    
kernel32!BaseThreadInitThunk+22    
ntdll!RtlUserThreadStart+34

This is the second thread in error (from DebugDiag) : Error is : In App.exe.6860.dmp GC is running in this process. The Thread that triggered the GC is 1502 I rename the application, is not App.exe :D

Entry point   clr!Thread::intermediateThreadProc 
Create time   16/11/2020 18:13:27 
Time spent in user mode   0 Days 21:36:08.437 
Time spent in kernel mode   0 Days 01:01:11.015 

.NET Call Stack

[[HelperMethodFrame]] 
Matrox.MatroxImagingLibrary.MIL_INTArrayToIntArrayConverter..ctor(Matrox.MatroxImagingLibrary.MIL_INT[])+2d 
Matrox.MatroxImagingLibrary.MIL.MimGetResult(Matrox.MatroxImagingLibrary.MIL_ID, Int64, Matrox.MatroxImagingLibrary.MIL_INT[])+2e 
App.VisionEngine.DetectionPresence()+373 
App.VisionEngine.th_ActivationP_Processus()+b19 
App.ClassVisionEngine.b__238_0()+25 
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+172 
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+15 
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+55 
mscorlib_ni!System.Threading.ThreadHelper.ThreadStart()+55 
[[GCFrame]] 
[[DebuggerU2MCatchHandlerFrame]] 

Source

ntdll!NtWaitForSingleObject+a    
KERNELBASE!WaitForSingleObjectEx+94    
clr!CLREventWaitHelper2+3c    
clr!CLREventWaitHelper+1f    
clr!CLREventBase::WaitEx+71    
clr!SVR::gc_heap::wait_for_gc_done+5a    
clr!SVR::GCHeap::GarbageCollectGeneration+ed    
clr!SVR::gc_heap::trigger_gc_for_alloc+34    
clr!SVR::GCHeap::Alloc+225    
clr!JIT_NewArr1+6dd    
Matrox.MatroxImagingLibrary.MIL_INTArrayToIntArrayConverter..ctor(Matrox.MatroxImagingLibrary.MIL_INT[])+2d    
Matrox.MatroxImagingLibrary.MIL.MimGetResult(Matrox.MatroxImagingLibrary.MIL_ID, Int64, Matrox.MatroxImagingLibrary.MIL_INT[])+2e    
App.VisionEngine.DetectionPresence()+373    
App.VisionEngine.th_ActivationP_Processus()+b19    
App.VisionEngine.<Start>b__238_0()+25    
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+172    
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+15    
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+55    
mscorlib_ni!System.Threading.ThreadHelper.ThreadStart()+55    
clr!CallDescrWorkerInternal+83    
clr!CallDescrWorkerWithHandler+4e    
clr!MethodDescCallSite::CallTargetWorker+102    
clr!ThreadNative::KickOffThread_Worker+fffff02f    
clr!ManagedThreadBase_DispatchInner+40    
clr!ManagedThreadBase_DispatchMiddle+6c    
clr!ManagedThreadBase_DispatchOuter+4c    
clr!ManagedThreadBase_FullTransitionWithAD+2f    
clr!ThreadNative::KickOffThread+e6    
clr!Thread::intermediateThreadProc+8b    
kernel32!BaseThreadInitThunk+22    
ntdll!RtlUserThreadStart+34 

Matrox is from the MIL.lib

I'm stuck on this crash, someone can give me some advices

Thanks

c#
multithreading
access-violation
asked on Stack Overflow Feb 11, 2021 by Nical • edited Feb 11, 2021 by Nical

1 Answer

2

"which use some IntPtr in our app." Assuming it's your app not the library (and this assumption is not completely dubious), check for NULLs everywhere you pass IntPtr to the library. Despite writing in C#, you are playing by unmanaged rules now.

The specific heap trash also suggests the possibility of passing an array to a native function that retains the array, and you didn't pin the array with a GCHandle first.

answered on Stack Overflow Feb 11, 2021 by Joshua

User contributions licensed under CC BY-SA 3.0