You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
C# jagged arrays and lists make Unity crash the second time #1713
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.
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.
usingSystem.Collections.Generic;usingUnityEngine;usingSystem.IO;usingPython.Runtime;publicclassMinimalExample:MonoBehaviour{float[,]twoDimArray=null;float[][]jaggedArray=null;List<float[]>listArray=newList<float[]>();voidStart(){//Adjust the line below to your target python version in the correct folderRuntime.PythonDLL=Application.dataPath+"/StreamingAssets/embeddedPy/python38.dll";for(inti=0;i<2;i++){float[]temp={1.2345679f,9.87654321f,1.23456789f};listArray.Add(temp);}twoDimArray=newfloat[,]{{1.2345679f,9.87654321f,1.23456789f},{1.2345679f,9.87654321f,1.23456789f}};jaggedArray=listArray.ToArray();SendToPython(twoDimArray,jaggedArray,listArray);}voidSendToPython(float[,]ex2,float[][]ex3,List<float[]>ex4){using(Py.GIL()){dynamicpy_sys=Py.Import("sys");stringsite_pkg="Lib\\site-packages";py_sys.path.insert(0,Path.Combine(Application.streamingAssetsPath,site_pkg));dynamicpythonScript=Py.Import("MinimalExample");//If we use ex2 here as input, restarting inside unity works. Restarting does not work for ex3 and ex4dynamicreturnedValue=pythonScript.ReturnValue(ex2);Debug.Log(returnedValue);}}}
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.
@lostmsu , Thanks for your quick reply and you are completely right. I merged two projects and apparently had an older dll of PythonNet included. However, I just reloaded it with the given version, updated the code (see code above for updated version), however the exact same problem still exists.
I do see a similar issue was seen in fix #958, however that option is not available anymore as far as I can see from the overload methods. And next to that, restarting works for normal arrays as shown above.
Activity
lostmsu commentedon Mar 4, 2022
@Zulex something is fishy. 3.0.0-preview2022-03-03 does not have
ShutdownModeZulex commentedon Mar 4, 2022
@lostmsu , Thanks for your quick reply and you are completely right. I merged two projects and apparently had an older dll of PythonNet included. However, I just reloaded it with the given version, updated the code (see code above for updated version), however the exact same problem still exists.
I do see a similar issue was seen in fix #958, however that option is not available anymore as far as I can see from the overload methods. And next to that, restarting works for normal arrays as shown above.