operator<<(ostream&, const MPoint&) causing a crash

operator<<(ostream&, const MPoint&) causing a crash

Anonymous
Not applicable
1,669 Views
6 Replies
Message 1 of 7

operator<<(ostream&, const MPoint&) causing a crash

Anonymous
Not applicable

Hi,

   I am trying to use print debugging to fix my plugin.

For some reason, Maya2106SP6 on Win10 is crashing whenever I call:

 

OPENMAYA_EXPORT std::ostream& operator<< ( std::ostream &  os,     const MPointp     )  

 

For now, I'm working around it but I'm wondering what I can do to make this work.

Do I need to define OPENMAYA_EXPORT somewhere?

Where is the operator<< actually defined?

 

Thank you!

Ben

0 Likes
Accepted solutions (1)
1,670 Views
6 Replies
Replies (6)
Message 2 of 7

cheng_xi_li
Autodesk Support
Autodesk Support

Hi ben,

 

I tried with std::ostream& operator<< ( std::ostream &  os,  const MPoint &p) in Maya 2016SP6. It works fine. operator <<  is overloaded in our library. OPENMAYA_EXPORT is basically dllimport macro. The overloaded operator just puts MPoint.x, y ,z ,w into the stream in a format. Thus, it shouldn't have any problems. It could be system environment issues, compiler version issue or any other kinds of problem.

 

Yours,

Li

0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi Cheng,

   Thank you for looking into it.

I ran a very simple test to figure out why operator<<(std::ostream& os, const MPoint& pt) was causing a crash:

    MPoint pt(0, 1, 2);
    std::cout << "pt = " << pt << std::endl;

My preprocessor defines are:

WIN32
_WIN64
_WINDOWS
_USRDLL
NT_PLUGIN
REQUIRE_IOSTREAM
MODULE_NAME="$(TargetFileName)"

I ran mayapy using Depends32.exe and loaded the plugin into it. I attached the printout of all of the module load calls.

Interestingly, my plugin depends on MSVCP140D.DLL but the exception occurs in MSCVP110.DLL.

 

I'm wondering if its the DLL mismatch which is causing the crash....

 

0 Likes
Message 4 of 7

Anonymous
Not applicable
Also, this problem doesnt effect MString, only MPoint and MVector as far as I can see.
0 Likes
Message 5 of 7

Anonymous
Not applicable
More info, I got the symbol libraries loaded for windows:
Here's the callstack below my function call (in SampleInteriorPointsCmd::doIt):

msvcp110.dll!std::ios_base::getloc(void) Unknown
msvcp110.dll!std::basic_ostream<char,struct std::char_traits<char> >::operator<<(double) Unknown
> OpenMaya.dll!00007fff350833b9() Unknown
v3d_convert.mll!SampleInteriorPointsCmd::doIt(const MArgList & args) Line 198 C++

Also, the exception thrown is:
Exception thrown at 0x00007FFF7AC4AAEB (msvcp110.dll) in maya.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

0 Likes
Message 6 of 7

Anonymous
Not applicable

I fixed the problem by reimplementing operator<<() for MPoint and MVector but it's not a great solution.

I think that the underlying problem is that OpenMaya.dll is linking to MSCVP110.DLL and my plugin is linking to MSCVP140D.DLL leading to ??DLL hell??

 

Not sure though

0 Likes
Message 7 of 7

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi ben,

 

It is possible when using different version msvc will cause this problem.

 

We recommend to use MSVC110(Visual studio 2012) to compile your Maya plugin for 2016 and 2017. For more details of building environment, please check our document.

 

Yours,

Li

0 Likes