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.

Error when unloading plugin that uses winsock2

Error when unloading plugin that uses winsock2

nosc19
Participant Participant
635 Views
5 Replies
Message 1 of 6

Error when unloading plugin that uses winsock2

nosc19
Participant
Participant

Hello. I'm currently creating a plugin that uses winsock2 for a peer to peer tcp-connection. When I try to unload my plugin, Maya crashes and produces the log-file that I have uploaded here. I have concluded that this crash is caused somehow when I include the code that tries to connect a socket to an address and port by using the winsock functions socket() and connect(). I'm very lost of why this is happening only when unloading the plugin, but not during the connect() calls etc. The connect() and socket() and most other winsock calls are made in a function that is called using the MThreadAsync::CreateTask() and later exited correctly.

 

Also, I know where it is crashing. It is crashing when deleting my connection instance during the uninitialize-function of the plugin. My connection instance contains all the winsock data such as the sockets, addrinfo etc.

0 Likes
636 Views
5 Replies
Replies (5)
Message 2 of 6

zewt
Collaborator
Collaborator

A mutex is throwing a debug assertion.  There should be more info if you attach a debugger to Maya while it's running.  The only error I can think of off the top of my head would be destroying the mutex while it's locked.

 

0 Likes
Message 3 of 6

nosc19
Participant
Participant
Ah okay. Will look into that a bit more. But how did you know it was the mutex throwing a debug assertion?
0 Likes
Message 4 of 6

nosc19
Participant
Participant

I've now tried to attach a debugger. But unfortunately it won't allow me to stop at the breakpoint (see picture 1). I'm starting my plugin, then starting local windows debugger with breakpoint and then pressing unload plugin (which makes maya crash (see picture 2)). Idk why it doesnt work. Maybe you know?

nosc19_0-1649968105385.png

nosc19_0-1649968306355.png

 

0 Likes
Message 5 of 6

zewt
Collaborator
Collaborator

The top of the stack trace points to mutex code:

 

Location: ucrtbased.dll__threadid + 203 bytes
Location: ucrtbased.dllabort + 1D bytes
Location: MSVCP140D.dll_Thrd_abort + 41 bytes
Location: MSVCP140D.dll_Mtx_destroy_in_situ + 22 bytes
Location: NetMaya.mllstd::_Mutex_base::~_Mutex_base Line 45
Location: NetMaya.mllstd::mutex::~mutex + 1F bytes

Location: NetMaya.mllConnectionPTP::~ConnectionPTP Line 306
Location: NetMaya.mllConnectionPTP::`scalar deleting destructor' + 23 bytes
Location: NetMaya.mlluninitializePlugin Line 781

 

Mtx_destroy_in_situ is an internal function that's called when mutexes are destroyed, and it's firing an abort for some reason.  You can also check the line numbers it lists for each stack frame.

 

If Visual Studio shows an empty circle like that for a breakpoint, it means the source file doesn't match up with the loaded executable, or the plugin isn't loaded yet.

 

You should be able to press "retry" (whichever of those buttons that corresponds to in your language), and it'll hit a breakpoint in the debugger so you can see where it's happening.  It should match the line numbers in the stack trace.

0 Likes
Message 6 of 6

nosc19
Participant
Participant

Okay, I forgot to set "DebuggableAttribute" in vs. Now I don't get the empty circle. But now it just crashes when I press try again and it wont step into the uninit function.

0 Likes