Title: C# jagged arrays and lists make Unity crash the second time · Issue #1713 · pythonnet/pythonnet · GitHub
Open Graph Title: C# jagged arrays and lists make Unity crash the second time · Issue #1713 · pythonnet/pythonnet
X Title: C# jagged arrays and lists make Unity crash the second time · Issue #1713 · pythonnet/pythonnet
Description: Environment Pythonnet version: 3.0.0-preview2022-03-03 Python version: 3.8.9 Operating System: Windows 10 .NET Runtime: 4 Unity 2020.3.12f1 Details Describe what you were trying to get done. Trying to send a jagged array or List of float...
Open Graph Description: Environment Pythonnet version: 3.0.0-preview2022-03-03 Python version: 3.8.9 Operating System: Windows 10 .NET Runtime: 4 Unity 2020.3.12f1 Details Describe what you were trying to get done. Trying...
X Description: Environment Pythonnet version: 3.0.0-preview2022-03-03 Python version: 3.8.9 Operating System: Windows 10 .NET Runtime: 4 Unity 2020.3.12f1 Details Describe what you were trying to get done. Trying...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/1713
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"C# jagged arrays and lists make Unity crash the second time","articleBody":"### Environment\r\n\r\n- Pythonnet version: 3.0.0-preview2022-03-03\r\n- Python version: 3.8.9\r\n- Operating System: Windows 10\r\n- .NET Runtime: 4\r\n- Unity 2020.3.12f1\r\n\r\n### Details\r\n\r\n- Describe what you were trying to get done.\r\n\r\n Trying to send a jagged array or List of float 1D array to Python via C# in Unity. This works the first time I press play in Unity but crashes on the second time without any errors.\r\n\r\n- See below for a C# script that creates a normal 2D array, a jagged array and a listarray. If I send the normal array, it works fine restarting. However the jagged array and list do make unity crash if I press play for a second time.\r\n\r\n```C#\r\nusing System.Collections.Generic;\r\nusing UnityEngine;\r\nusing System.IO;\r\nusing Python.Runtime;\r\n\r\npublic class MinimalExample : MonoBehaviour\r\n{\r\n float[,] twoDimArray = null;\r\n float[][] jaggedArray = null;\r\n List\u003cfloat[]\u003e listArray = new List\u003cfloat[]\u003e();\r\n\r\n void Start()\r\n {\r\n //Adjust the line below to your target python version in the correct folder\r\n Runtime.PythonDLL = Application.dataPath + \"/StreamingAssets/embeddedPy/python38.dll\";\r\n\r\n for (int i = 0; i\u003c2; i++)\r\n {\r\n float[] temp = { 1.2345679f, 9.87654321f, 1.23456789f};\r\n listArray.Add(temp);\r\n }\r\n\r\n twoDimArray = new float[,] { { 1.2345679f, 9.87654321f, 1.23456789f }, { 1.2345679f, 9.87654321f, 1.23456789f } };\r\n\r\n jaggedArray = listArray.ToArray();\r\n SendToPython(twoDimArray, jaggedArray, listArray);\r\n }\r\n\r\n void SendToPython(float[,] ex2, float[][] ex3, List\u003cfloat[]\u003e ex4)\r\n {\r\n\r\n using (Py.GIL())\r\n {\r\n dynamic py_sys = Py.Import(\"sys\");\r\n string site_pkg = \"Lib\\\\site-packages\";\r\n py_sys.path.insert(0, Path.Combine(Application.streamingAssetsPath, site_pkg));\r\n dynamic pythonScript = Py.Import(\"MinimalExample\");\r\n\r\n //If we use ex2 here as input, restarting inside unity works. Restarting does not work for ex3 and ex4\r\n dynamic returnedValue = pythonScript.ReturnValue(ex2); \r\n\r\n Debug.Log(returnedValue);\r\n }\r\n }\r\n}\r\n```\r\n\r\n```python\r\nimport numpy as np\r\n\r\ndef ReturnValue(data):\r\n result = np.asarray(data)\r\n return result\r\n```\r\n\r\n- A simple solution is to transform my jagged arrays and lists to normal arrays. However I was wondering if I am doing something wrong or this is indeed an unknown bug. \r\n\r\n\r\n","author":{"url":"https://github.com/Zulex","@type":"Person","name":"Zulex"},"datePublished":"2022-03-04T18:41:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1713/pythonnet/issues/1713"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:691775d8-b1a3-5855-2e2e-87568a9f0085 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B4D8:1B1EBD:2FCAC70:405DA07:697083A1 |
| html-safe-nonce | 75a90ae46348edec33e8c266bdb3f1f51d524216142dc4d6e29feba061a51611 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNEQ4OjFCMUVCRDoyRkNBQzcwOjQwNURBMDc6Njk3MDgzQTEiLCJ2aXNpdG9yX2lkIjoiNjUzMTc3MzUxMzc2Nzg3OTU4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c46d7aa2856e9190f22bdca3bc7b56ffdaa76a8694761eb7ef7eb577e60b5e4a |
| hovercard-subject-tag | issue:1159938548 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/1713/issue_layout |
| twitter:image | https://opengraph.githubassets.com/75b4804f76d07a3fc34879443e20a29a84232c9fa55b1e01d06581d1c0b9e282/pythonnet/pythonnet/issues/1713 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/75b4804f76d07a3fc34879443e20a29a84232c9fa55b1e01d06581d1c0b9e282/pythonnet/pythonnet/issues/1713 |
| og:image:alt | Environment Pythonnet version: 3.0.0-preview2022-03-03 Python version: 3.8.9 Operating System: Windows 10 .NET Runtime: 4 Unity 2020.3.12f1 Details Describe what you were trying to get done. Trying... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Zulex |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9920a62ba22d06470388e2904804fb7e5ec51c9e35f81784e9191394c74b2bd2 |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7d6181066430cc06553c8396ca201e194ae33cb9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width