Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
0
Question by kdedeurw · Apr 08 at 08:13 AM · dllcrashingnative pluginnativeinconsistent

Calling functions from Native DLL (C++) inconsistently crashes Unity

Hi,

I created a custom C++ dll as a wrapper for the e57Format library that reads in data from .e57 point cloud files. (x64 only)

(https://github.com/asmaloney/libE57Format)

The DLL depends on other external DLLs such as xerces-c XML (also x64)

Everything is able to run fine without any issues, however this doesn't always happen.

Sometimes when I attach the debugger and step through some code, it runs fine, other times when I do the same, it just straight up crashes.

And sometimes when I press "Play" without the debugger or without breakpoints, it also just straight up crashes. However, this is not always the case, since the same code can sometimes run just fine without any changes.

This might indicate a data race scenario, where either threads are run in an incorrect order or DLLs being loaded in incorrectly.

Note: I don't use multithreading in the DLL.

The crash is shown below:

alt text

All DLLs are placed in Assets/Plugins and I do not get the Dllnotfoundexception

I am using the C++ debuglogger solution from: https://forum.unity.com/threads/log-to-console-from-c-dll.953498/

I also call functions in C# from the C++ dll through delegate/function pointers and marshal data from C++ to C#, which already shows correct results. (Unsafe code + unsafe keyword)

I've tried:

  • enabling load on startup

  • platform settings to Windows and x64 only

  • calling the function from a different thread

None of these solutions have worked so far. Any help would be appreciated.

Note: I seem to not find any logs from this, maybe I am looking in the wrong directories?

crash.jpg (29.1 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by kdedeurw · Apr 15 at 02:03 PM

Update: (+ Fix)

I managed to stop the inconsistent crashing.

The issue was due to the absence of exception handling (try-catch-throw).

I do this on the C++ side and return an errorcode int back to C# to backtrack what the exception could be.

(Sometimes the e57 reader wouldn't open and would therefore throw an exception, which I didn't catch, hence the inconsistent crashing)

However, sending a "native" std::exception from C++ to C#/Unity will crash Unity with the same crash as mentioned before.

(C++ code snippet below: The Checke57Error returns an errorcode (int) ranging from 0 (success code, shouldn't ever get returned) to 50, I return this to C# code and log it in the console as an extra debug measure.) alt text


capture.jpg (30.7 kB)
Comment
Add comment · Share
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

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

180 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

Related Questions

Reloading native plugins 3 Answers

Native DLL saying FileNotFoundException 2 Answers

Editor freezing with multithreaded DLL native plugin in Release but not in Debug 2 Answers

method body replaced by unityLinker.exe with a notsupportedexception 1 Answer

Move C# scripts to DLLs targeting UWP/Net deployment: the type or namespace 'SerializeAttribute/Serializable' could not be found? 1 Answer


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