20tab / UnrealEnginePython

Embed Python in Unreal Engine 4
MIT License
2.7k stars 737 forks source link

Using davidjo/UnrealEnginePython on Linux, python 3.8 and Unreal 4.25.3 crashes when loading UnrealEnginePython plugin #861

Open hradec opened 3 years ago

hradec commented 3 years ago

So, I got davidjo/UnrealEnginePython to build successfully on Arch Linux, python 3.8 and Unreal 4.25.3. It does build without problem, but when Unreal tries to load the plugin, it crashes on line UnrealEnginePython/Source/UnrealEnginePython/Private/UnrealEnginePython.cpp:529.

Examining the source, the crash is because the code tries to retrieve the dictionary of a module, but the module pointer is empty. By examining the log, right before the crash, I've found this:

[2020.09.24-21.41.38:492][  0]LogPython: Python Scripts search path: .
[2020.09.24-21.41.38:492][  0]LogPython: Python Scripts search path: ???
[2020.09.24-21.41.38:492][  0]LogPython: Python VM initialized: 3.8.0 (default, Oct 23 2019, 18:51:26) 

It does seem like python search path is empty, which would explain why it can't load the module and the pointer returns empty. I've tried to booth unset PYTHONPATH (hoping the python vm would use the default one) and setting to the proper search path, but no matter what I do with PYTHONPATH, the message above never changes. (actually, the ??? changes to some other garbage, which probably means it's displaying an uninitialized string?!)

Anyhow... if someone knows what the problem is, I would appreciate the help! I'll start digging in the code to trace what's going on.

hradec commented 3 years ago

Just an update.

I was able to build using Python 2.7.12, after removing -Werror from LinuxToolChain.cs and setting

[/Script/LinuxTargetPlatform.LinuxTargetSettings]
TargetArchitecture=X86_64UnknownLinuxGnu

into Config/DefaultEngine.ini. (Building with python 2.7.x generates a lot of no-harmful warnings and having -Werror prevents it from building)

With python 2.7.x davidjo/UnrealEnginePython plugin seems to work just fine in Unreal 4.25.3 on Linux. The Python Scripts search path: ??? still shows, but doesn't crash on UnrealEnginePython.cpp line 529.

I'll stop debugging with python 3.8 for now, since I do prefer to use python 2.7 anyways... But it does seem to have something going on when building with 3.8.

i-am-nut commented 3 years ago

It's nice! I think nobody else has managed to do it.

I'm just a dude wandering around here wondering if this project is totally abandoned or not.

Are you being able to use this plugin without little issues? like editor crash, running succesfully doc examples and whatnot?

hradec commented 3 years ago

Yep.. no problem so far!

On Mon, Sep 28, 2020 at 9:02 AM Emerson Junior notifications@github.com wrote:

It's nice! I'm just a dude wandering around here wondering if this project is totally abandoned or not. Are you being able to use this plugin without little issues? like editor crash, running succesfully doc examples and whatnot?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/20tab/UnrealEnginePython/issues/861#issuecomment-700128642, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGE6V2TV5IB54HPVY6JXULSICXTDANCNFSM4RYZ5WRQ .

i-am-nut commented 3 years ago

In case of applying the same modifications for working on Windows version, what would be the steps?

hradec commented 3 years ago

Well, on windows the plugin built just fine against python27.

On Tue, Sep 29, 2020 at 8:52 AM Emerson Junior notifications@github.com wrote:

In case of applying the same modifications to work on the plugin Windows version, what would be the steps?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/20tab/UnrealEnginePython/issues/861#issuecomment-700798687, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGE6VZKXZD4ZJJ4DJSBNZ3SIH7CDANCNFSM4RYZ5WRQ .

davidjo commented 3 years ago

The following patch fixes the Python Scripts search path print and hopefully fixes the python 3 crash. (Although for me on Ubuntu 20.04 LTS using system python 3.8 and UE 4.25.3 I dont get a crash - but do get bad log of Python Scripts search path: . twice)

UnrealEnginePython.cpp.patch.txt

davidjo commented 3 years ago

So I now dont think the issue is the bad Python Scripts search path prints - they have been bad since for a while (last correct print I have is late 2017 UE 4.18 python 3.6) - for me the bad prints are from 4.21 and python 3.6 - and it appears to be a pure printing error - the value is saved correctly.

The following patch corrects the print error. UnrealEnginePython.cpp.patch.txt