mcpiroman / UnityNativeTool

Allows to unload native plugins in Unity3d editor
MIT License
184 stars 19 forks source link

Hanging on quit #5

Closed kjjohnsen closed 5 years ago

kjjohnsen commented 5 years ago

Thanks so much for your efforts. My (native rendering) plugin works fine until I end the game (click play again), at which point it freezes the Unity editor and I have to kill and restart. The plugin uses many threads internally, which are cleaned up OnApplicationQuit. I saw the comment related to threads running past OnApplicationQuit in the readme, and was wondering if this could be related. Note, the plugin starts and stops without your tool enabled. The plugin itself relies on several DLLs that are in the Assets folder (not sure if this is somehow related).

mcpiroman commented 5 years ago

The plugin uses many threads internally, which are cleaned up OnApplicationQuit

Not sure what do you mean by saying internally. If these are native threads created inside plugin, then this tool should have nothing to do with them (and so should work). If these are managed threads created from C# side, then there indeed might be some issues.

Note, the plugin starts and stops without your tool enabled.

Could you explain that? This tool is designed to run before the concerned plugins are loaded, if you somehow bootstrap them earlier this shouldn't work at all.

Also, have you enabled 'thread safe' mode in options? It is disabled by default.

kjjohnsen commented 5 years ago

The plugin uses many threads internally, which are cleaned up OnApplicationQuit

Not sure what do you mean by saying internally. If these are native threads created inside plugin, then this tool should have nothing to do with them (and so should work). If these are managed threads created from C# side, then there indeed might be some issues. Yes, these are native threads created inside the plugin.

Note, the plugin starts and stops without your tool enabled.

Could you explain that? This tool is designed to run before the concerned plugins are loaded, if you somehow bootstrap them earlier this shouldn't work at all. I mean that the Unity project would start and stop without issue before installing your package and renaming plugins to __pluginname.

Also, have you enabled 'thread safe' mode in options? It is disabled by default.

Yes. I have tried all combinations I can toggle. All of them have the same result of causing Unity Editor to freeze when play is stopped. I suspect that the plugin is still retaining some resources and becomes unhappy when unloaded. I'll keep looking deeper and let you know.

kjjohnsen commented 5 years ago

I added a 2s delay in the plugin after stopping all native threads within the plugin, and now everything seems to work properly! This wasn't an issue at all with your code. Thanks for the help and for the great plugin!