ModOrganizer2 / modorganizer

Mod manager for various PC games. Discord Server: https://discord.gg/ewUVAqyrQX if you would like to be more involved
http://www.nexusmods.com/skyrimspecialedition/mods/6194
GNU General Public License v3.0
2.06k stars 155 forks source link

Python startApplication() Doesn't return 0 on failure #2057

Open wxMichael opened 5 days ago

wxMichael commented 5 days ago

The problem:

The documentation states that startApplication returns "The handle to the started application, or 0 if the application failed to start." If the executable fails to launch, the handle for MO2 is returned instead of 0. Using waitForApplication with the returned handle will show the PID for MO2 and wait forever.

To Reproduce:

Run startApplication with a bogus string to trigger a failed start and check the return value. I created a simple plugin to reproduce the issue: https://gist.github.com/wxMichael/f8d05ab4b2f07a547d1e8c57060266d5 Compare the PID on the wait screen to the PID from the error message or Task Manager.

Environment:

USVFS:

https://gist.github.com/wxMichael/8a71088b7f5ad55961ce162529a45d19

MO Interface:

https://gist.github.com/wxMichael/29a4bd7fd1afa830a3333f15a3c040f2

Holt59 commented 5 days ago

The documentation is wrong for this but

Using waitForApplication with the returned handle will show the PID for MO2 and wait forever.

...is probably not true. The returned handle is INVALID_HANDLE_VALUE, which is ((HANDLE)(LONG_PTR)-1), so you probably get UB or something close to that when trying to call waitForApplication with it.

I will update the documentation and expose INVALID_HANDLE_VALUE to Python so that developers can compare the returned value to something.