Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Mike 12 · Dec 01, 2010 at 09:37 PM · monodevelopmono

Passing Arrays as Parameters Between Functions in C# and C++ dll's within Unity

Here's the sample code where the external C++ function is declared in the C# code:

[DllImport("PhysicsEngine")]
private static extern void CalculateTrajectory(float deltaT, float muzzleVelocity, float theta, float phi, float[] origin, float[,] trajectory, int size);

And, here's where the function is called:

            int size = 20;
            float deltaT = 0.02f;
            float muzzleVelocity = 900.0f;
            float[] origin = new float[3];
            origin[0] = -200.0f;
            origin[1] = 1.242f;
            origin[2] = 1000.0f;
            float theta = 0.0f;
            float phi = 0.0f;
            float maxRange = 1000.0f;
            float[,] trajectory = new float[size, 3];
CalculateTrajectory(deltaT, muzzleVelocity, theta, phi, origin, trajectory, size);

Here's the original C++ function definition's name and parameters:

void EXPORT_API CalculateTrajectory(float deltaT, float muzzleVelocity, float theta, float phi, float* origin, float** trajectory, int size)

The problem is that when I try to run the game in Unity or my own personal C# tester program, both programs crash. Why is that? Has anyone else successfully passed arrays as parameters between Unity and their own C++ dll's? If so, then please let me know so that I and others may benefit from your knowledge. Thank-you.

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
2
Best Answer

Answer by SteveFSP · Dec 02, 2010 at 03:43 AM

The answer I gave to your other question has some links which may be helpful.

There is a link to an MSDN page which discusses marshaling arrays. Also, there is a link to some code I use to pass arrays back and forth between Unity and a C++ plugin. (Though I haven't attempted multi-dimensional arrays.)

From experience, I strongly recommend testing all marshaling code outside Unity in an IDE. Once it is working there without any errors, then move it into Unity. You can avoid a lot of the hassle since your external IDE will usually give you better error responses than Unity can provide.

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

No one has followed this question yet.

Related Questions

Monodevelop Go to declaration bug 3 Answers

MonoDevelop 2.8.2 Crash 1 Answer

Can I prevent MonoDevelop's 'Find in Files' from crashing? 2 Answers

Can't find MonoDevelop. Unity 4.5.2 1 Answer

Change MonoDevelop c# compiler output language 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