Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Maya Freezing on unloading a DLL

Maya Freezing on unloading a DLL

Anonymous
Not applicable
1,108 Views
4 Replies
Message 1 of 5

Maya Freezing on unloading a DLL

Anonymous
Not applicable

Hello,

 

I am trying to use a custom plugin with dependency on an external DLL, but when I close the application, Maya freezes and I have to shut down it from the task manager.

 

This issue happened on Maya 2018 and 2016.

 

I can use the DLL normally in a standalone application, and the DLL is working as expected in the Plugin. The problem happens only when closing the application.

 

I do nothing special when unloading/loading the DLL, so I was expecting that to be entirely handled by Maya and/or the OS.

 

When I unload the plugin (via plugin manager), the DLL is not being unloaded. I can load/reload the plugin several times without any problems.

 

After I included the DLL in the project, I can not unload the plugin/recompile/load again. Visual Studio complains that it can not overwrite the MLL file.

(The checkbox is unchecked and I tried to flush the undo list, but the problem remains)

Before adding the DLL, this unload/recompile/reload process had no problems. I think it might be related to the Freezing issue.

 

 

Any ideas about what might be wrong?

 

Thank you.

 

0 Likes
Accepted solutions (1)
1,109 Views
4 Replies
Replies (4)
Message 2 of 5

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

Please try to unload the dll manually with FreeLibrary in the unloadplugin?

 

If it had failed to unload it, you could use GetLastError to check what is wrong.

 

Could you give use info about what does that dll have done and how it compiles? A reproducible sample will be very helpful.

 

Yours,

Li

0 Likes
Message 3 of 5

Anonymous
Not applicable

When unloading manually with FreeLibrary, the application freezes after I uncheck the checkbox in the Plug-in Manager. No error is returning and it is printing everything until the end of unload, so the application is hanging somewhere after this point.

 

The project is too complex to reduce, but basically, the plugin depends on a DLL and this DLL itself depends on other DLLs. Some of those secondary dependencies are CUDA, Embree related libraries. We are not making anything about loading/unloading modules, everything is being handled by the OS.

 

In the plugin, we are using smart pointers to keep objects allocated by the DLL. I suppose they are deallocated together with the userNode data before pluginUnload. If third party dlls are allocating static objects and not deleting them, that might be a source for this problem..

 

I am assuming this is too involved to be easily answered here, so I would just like to know if Maya would have a problem with those secondary dependencies, specially if Maya itself already depends on them?

 

thank you

0 Likes
Message 4 of 5

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

I don't think there could be a problem with secondary dependencies. For example, you've mentioned CUDA, the products like IRay, they are also refereing CUDA libraries in their products as a secondary reference too.

 

You've mentioned smart pointers. It might be an issue, I've experienced a crash casued by smart pointer in the devkit sample. The workspaceControlCmd sample in 2018 devkit needs to delete the QPointer to prevent Maya crashes during the finialize when unloading the plugin with its windows openned. It will be destroyed after all of its children is released. But when it is about to release, the dll has been already unloaded and its deconstructor is invalid. I am wondering if this kind of issue would be happened in your case.

 

Another thing is, if there are threads created inside of your library, it should be calling FreeLibraryAndExitThread instead of FreeLibrary and ExitThread to prevent race condition.

 

I could come up with these two ideas now, hope it helps.

 

Yours,

Li

0 Likes
Message 5 of 5

Anonymous
Not applicable

That could definitely be an issue. I wasn't considering this before!

 

After all, the source of the problem was an static library being linked by the plugin (totally unrelated to the DLL).

I don't know the details of this lib implementation, but it seems that it was just a matter of changing some project settings.

 

Thanks for your help!

Vladimir!

 

 

0 Likes