Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by FC_Alessandro · Apr 19, 2021 at 02:29 PM · errormemory managementaccess denied

Direct3D 12 Memory Allocation Crash

Hello everyone, I'm really stumped on this sporadic crash that happens in my app and I'm running out of ideas. I keep getting a memory access violation error, my stack trace has a couple of variations but always ends up with D3D12DescriptorCache::Allocate.

In short my app is passing 2 textures as native array pointers to a custom c++ dll that then writes in them before I call Texture2D.Apply in unity. This was something I ended up doing cause I needed to handle multiple devices at a high framerate that was not possible with unity's standard LoadData function. here is my code:

Here is a snippet of my unity code:

void UpdateFrame() { try { int newFrameResult = 0;

         if(!isDisabled)
         {
             texDataColor = colTex.GetRawTextureData<Color32>();
             texDataDepth = depthTex.GetRawTextureData<Color32>();
  
             unsafe
             {
                 IntPtr colorPtr = (IntPtr)NativeArrayUnsafeUtility.GetUnsafePtr(texDataColor);
                 IntPtr depthPtr = (IntPtr)NativeArrayUnsafeUtility.GetUnsafePtr(texDataDepth);
  
                 if(colorPtr != IntPtr.Zero && depthPtr != IntPtr.Zero)
                 {
                     newFrameResult = GetLatestLiveFrames(colorPtr, depthPtr, kinectIndex, resolution.x, resolution.y, offset, limitIR, maxDepthMM);
                 }
                 else
                 {
                     newFrameResult = 4;
                 }
             }
  
             if(newFrameResult == 1)
             {
                 colTex.Apply();
                 depthTex.Apply();
  
                 cShader.SetInt("w", resolution.x);
                 cShader.SetInt("h", resolution.y);
                 cShader.SetBool("flipX", flipX);
                 cShader.SetBool("flipY", flipY);
                 cShader.SetFloat("maxDepth", maxDepth);
  
                 cShader.Dispatch(0, resolution.x / 8, resolution.y / 8, 1);
                 cShader.Dispatch(1, resolution.x / 8, resolution.y / 8, 1);
             }
         }
         else
         {
             RenderTexture.active = colRT;
             GL.Clear(true, true, Color.black);
             RenderTexture.active = depthRT;
             GL.Clear(true, true, Color.black);
             RenderTexture.active = null;
  
             newFrameResult = 1;
         }
  
         if(texDataColor.IsCreated)
         {
             texDataColor.Dispose();
         }
  
         if(texDataDepth.IsCreated)
         {
             texDataDepth.Dispose();
         }
  
         if(newFrameResult == 1)
         {
             threeSlicePipeline.SendTexture(areaID, colRT, depthRT, this, !isDisabled);
         }
         else
         {
             switch(newFrameResult)
             {
                 case 0:
                     Debug.LogWarning($"{gameObject.name}: DLL Error Maybe null pointer! Skipping frame!");
                 break;
                 case 2:
                     if(useRecording)
                     {
                         Debug.LogWarning($"{gameObject.name}: DLL Error EOF! Skipping frame!");
                     }
                     else
                     {
                         Debug.LogWarning($"{gameObject.name}: DLL Error Timeout! Skipping frame!");
                     }
                 break;
                 case 3:
                     Debug.LogWarning($"{gameObject.name}: DLL Error Failed to pull capture! Skipping frame!");
                 break;
                 case 4:
                     Debug.LogWarning($"{gameObject.name}: Unity Error NULL pointer found! Skipping frame!");
                 break;
             }
  
             ReadyForNextFrame();
         }
     }
     catch
     {
         Debug.LogWarning($"{gameObject.name}: Error caught while pulling frame, skipping!");
  
         if(texDataColor.IsCreated)
         {
             texDataColor.Dispose();
         }
  
         if(texDataDepth.IsCreated)
         {
             texDataDepth.Dispose();
         }
  
         ReadyForNextFrame();
     }
 }

Here is a snippet of my DLL code:

void MemCopyImage(uint8_t* _buffer, uint8_t* _dst, int _dstW, int _dstH, int _srcXOffset, size_t _stride, int _pixelSizeInBytes) { uint8_t* ptr = _dst; uint8_t* sourcePtr = _buffer;

     int chunkHeight = _dstH / 12; //denominator MUST cleanly divide the height
  
     sourcePtr += _srcXOffset * _pixelSizeInBytes;
  
     if (sourcePtr == NULL || *sourcePtr == NULL) {
         OutputDebugString(L"Bad source pointer");
         return;
     }
  
     if (ptr == NULL || *ptr == NULL) {
         OutputDebugString(L"Bad destination pointer");
         return;
     }
  
     std::vector<std::thread> threads;
  
     std::mutex mtx;
  
     for (int i = 0; i < 12; i++) {
         threads.push_back(std::thread(CopyImageInThread, sourcePtr, ptr, _dstW, _dstH, _stride, _pixelSizeInBytes, i, chunkHeight, std::ref(mtx)));
     }
  
     for (auto& th : threads) {
         th.join();
     }
 }
  
 void CopyImageInThread(uint8_t* _sourceStart, uint8_t* _dstStart, int _dstW, int _dstH, size_t _stride, int _pixelSizeInBytes, int _index, int _chunkHeight, std::mutex& _mtx)
 {
     //image 0,0 position
     uint8_t* sourcePtr = _sourceStart;
     uint8_t* dstPtr = _dstStart;
  
     //strides
     size_t destinationStride = _dstW * _pixelSizeInBytes;
     size_t srcStride = _stride;
  
     //starting position for this chunk
     sourcePtr += srcStride * _index * _chunkHeight;
     dstPtr += destinationStride * _index * _chunkHeight;
  
     if (sourcePtr == NULL || *sourcePtr == NULL) {
         OutputDebugString(L"Bad source pointer");
         return;
     }
  
     if (dstPtr == NULL || *dstPtr == NULL) {
         OutputDebugString(L"Bad destination pointer");
         return;
     }
  
     if (IsBadHugeReadPtr(sourcePtr, destinationStride)) {
         OutputDebugString(L"Cant Read source pointer");
         return;
     }
  
     if (IsBadHugeWritePtr(dstPtr, destinationStride)) {
         OutputDebugString(L"Cant Read destination pointer");
         return;
     }
  
     _mtx.lock();
     for (int j = 0; j < _chunkHeight; j++)
     {
         try {
             memcpy(dstPtr, sourcePtr, destinationStride);
         }
         catch (...) {
             OutputDebugString(L"Problem writing line");
         }
  
         //move for the next copy
         sourcePtr += srcStride; //move by 1 row
         dstPtr += destinationStride;
     }
     _mtx.unlock();
 }

I attached the last couple of crash logs I got. As you can see on the code I have added plenty of null pointer checks and I designed the code so that there should never be any type of memory overlaps. The C# function only runs once the DLL is completely done with the previous cycle.

Any help on this issue would be much appreciated! link text

crashes.zip (355.4 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

198 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

FaceBook sdk Error Coding 0 Answers

error CS0201 1 Answer

warning CS0414: The private field `GameManagerSingleton.text' is assigned but its value is never used 0 Answers

Camera Switch error 0 Answers

Null Reference in script after having called other class without a null reference 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges