[Python.NET] Python.Net crash on assembly reload in Unity

David Lassonde david.lassonde at imaginary-spaces.com
Thu Aug 9 14:46:40 EDT 2018


Hi Viktoria,

As you know, I am working on fixes for these Domain Unload / Reload
crashes. I opened an issue against the public repo for the first crash (on
second init) here:

https://github.com/pythonnet/pythonnet/issues/714

I will do the same for the second crash (on second domain unload) when the
fix is approved in our own fork

Cheers!
David

On Mon, Jul 30, 2018 at 1:02 PM, Viktoria Kovecses <
viktoria.kovecses at imaginary-spaces.com> wrote:

> Hello,
>
> We are experiencing crashes when running Python.Net in the Unity 2018.2
> game engine. Specifically, after modifying a C# script in Unity, an
> automatic reload is triggered which results in a crash in Py_Finalize.
>
> Here are the repro steps:
> 0. Make sure to call PythonEngine.Shutdown on domain unload (otherwise it
> crashes earlier).
> 1. Create a Unity project and add the compiled Python.Net files (clr.pyd
> and Python.Runtime.dll) to the Assets folder
> 2. In Unity Player Settings (Edit > Project Settings > Player), under
> "Other Settings", make sure "Api Compatibility Level" is set to ".NET 4.x",
> and "Scripting Runtime Version" is set to ".NET 4.x Equivalent"
> 3. In Assets, create the following C# script (HelloWorld.cs):
>
> ```
> using UnityEditor;
> using UnityEngine;
> using Python.Runtime;
>
> class HelloWorld
> {
>     [MenuItem("Python/Hello")]
>     public static void CallHello()
>     {
>         using (Py.GIL())
>         {
>             string script = "import clr\n" +
>                 "clr.AddReference('UnityEngine.dll')\n" +
>                 "import UnityEngine\n" +
>                 "UnityEngine.Debug.Log('hello world!')\n";
>
>             PythonEngine.Exec(script);
>         }
>     }
> }
> ```
>
> 4. Run the script by selecting Python > Hello from the top menu
> --> This will log "hello world!" to the Unity console
>
> 5. Modify HelloWorld.cs script: change Hello to Hello 1 and trigger hot
> reloading of assemblies
> 6. run Python > Hello 1
> --> Logs in the console
>
> 7. Modify HelloWorld.cs script: change Hello 1 to Hello 2:
> --> crash in dict_traverse (garbage collection during Py_Finalize).
>
> Does anyone know what could be causing the crash and/or how to fix it?
>
> Any help is appreciated.
>
> Thank you,
> Viktoria
>
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> https://mail.python.org/mailman/listinfo/pythondotnet
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20180809/a0cfa00b/attachment.html>


More information about the PythonDotNet mailing list