none
BadImageFormatException : only with multi-thread RRS feed

  • Question

  • Hi,

    I have a C++ dll that I call from a C# class.

    Without multi-threading all is fine. But with several threads, it crash and give me the following error "BadImageFormatException".

    So, only the multi-thread version crash !!!

    What I do :

    1 - I convert some data from C# array to memory buffer (using Marshal.AllocHGlobal etc...)

    2 - I do the call to the DLL

    3 - I read back the result from the DLL

    4  - I free the memory buffer with Marshal.FreeHGlobal

    It crash at step 4 !!!!


    Here is my code :

     

       IntPtr ptrIntersections = Unmanaged.MarshallArray<gpuIntersection>(gpuIntersections);
       IntPtr ptrRays = Unmanaged.MarshallArray<gpuRay>(gpuRays.ToArray());
    
       //---- Trace
       CKernel_Trace(workgroupSize, ptrRays, ptrIntersections);
    
       //---- Read back to the buffer
       Unmanaged.ReadBackArray(ptrIntersections, _intersections);
    
       //---- Free
       Unmanaged.Free(ptrIntersections);
       Unmanaged.Free(ptrRays);
    

    Do you have an idea ?

     

    Thanks

     


    Pl01
    Thursday, May 20, 2010 11:29 AM

Answers

  • Do you know that the DLL is thread safe? Is it written by you or another vendor?

     


    Mattias, C# MVP
    • Proposed as answer by PolarLights01 Thursday, May 20, 2010 1:08 PM
    • Marked as answer by SamAgain Friday, May 21, 2010 7:18 AM
    Thursday, May 20, 2010 11:41 AM
    Moderator

All replies

  • Do you know that the DLL is thread safe? Is it written by you or another vendor?

     


    Mattias, C# MVP
    • Proposed as answer by PolarLights01 Thursday, May 20, 2010 1:08 PM
    • Marked as answer by SamAgain Friday, May 21, 2010 7:18 AM
    Thursday, May 20, 2010 11:41 AM
    Moderator
  • You're right, the DLL was not thread safe, it is now corrected.

    Thanks for your proposal


    PL01
    Thursday, May 20, 2010 1:07 PM