martedì 5 ottobre 2010

Compiling Connection plugin C source code to connect messiah's animation to Maya

I'd like to try out the messiahStudio 4.5 Demo version and connect it with Maya 2011. I downloaded the plugin source code to read it. Actually I didn't end to read it, because tons of code may take a lot of time, especially if we don't have a pale idea of how the program works.

I have Visual Studio C++ 2005 Express (if you want to compile the plugin with Visual c++ 2010 read this post) on my notebook, so I skipped the reading and gone directly to compile the plugin, just to have an idea of what kind of monster I have to deal with
I was able to compile the plugin (requirements, for me, Microsoft Platform SDK) after a few quick adjustments (the source is quite old). The most important:
  • References to file paths need to be resynced
  • #include <iostream> instead of #include <iostream.h>
  • "using namespace std;" in MH_NodeObject.cpp, messiahDeformerNode.cpp, pluginMain.cpp.
  • #include <windows.h> in MH_NodeObject.cpp and MH_System.cpp.
  • preprocessor option _DEBUG has to be removed from the release config
Visual Studio returned a few warnings (ie: #pragma warning(disable : 4996) or, better, _CRT_SECURE_NO_DEPRECATE in c++ preprocessor definitions to hide them, for now) but the project was generated.

The next step: test from Maya 2011. The output:
// messiahXform loaded //
// messiahDform loaded //
// messiahMaya loaded //
// messiah command loaded //
"// messiah started //" should appear here
// Error: source messiah; //
// Error: Cannot find file "messiah" for source statement. //
// Error: Cannot find procedure "pmgCreateMenu". //
// Warning: waitCursor stack empty // <- due to errors above

The errors in red are thrown when the plugin executes these calls to the MGlobal::executeCommand method:

// create the messiah menu
// sprintf(txt,"%s\\%s",path,"messiah.mel");
// MGlobal::sourceFile(txt);
stat = MGlobal::executeCommand("source messiah");
stat = MGlobal::executeCommand("pmgCreateMenu");

MGlobal is a static class which provides access to Maya's model. This class provides  also a method for executing MEL commands from within the Maya API. The plugin searches for a mel script (messiah.mel)  to create a menu.
In confirmation of this, I found out (very hard thing, there's not much about this application) that  Messiah 2.5 "added a new menu to the messiahmayaXX.mll plugins. There is a new MEL script in the main messiah directory named messiah.mel. Now, when the messiahmaya plugin is initialized, a new 'messiah' menu will automatically be added to the main maya menu allowing you at add the xformer, deformer or bring up the messiah interface. You can also change the scale or query the current scale."
Unfortunately there's not a mel script in the package I downloaded from projectmessiah.com.
For now I can't figure out how to fix the problem without the mel script and commenting out the code above is the best choice.
By the way,  a reading of interest  about the argument here.

Mel scripts apart, reading the code I realized that I had to take care  to define the host application name  (Maya) and  the module name (messiahMaya2011.mll) in params.h and in c++ preprocessor definitions. These constants are passed as arguments to a couple of functions (ie: messiahStart(...))
Now, the plugin should load messiahHOST.dll (ok) and then initialize Messiah.  Actually the application starts to load its libraries but, at a certain point, something wrong (code e06d7363: unhandled exception) happens  while executing MH_System::_beginSession():

First-chance exception at  0x00000000 in maya.exe: 0xc0000005: Access violation reading location  0x00000000.

"A first chance exception is basically when an exception occurs and gives your code the "first chance" of handling it in a catch() block. If you don't handle the exception, and no one else does then your code receives an unhandled exception and is exited".

Messiah loads its own library, Filemode.dll, and Maya crashes.



(294.a60): Access violation - code c0000005 (first chance)

First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=781c1bf8 ecx=7817ab1f edx=29e22d58 esi=01649779 edi=2d875ff8
eip=00000000 esp=01649740 ebp=000000da iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00210202
00000000 ?? ???
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Programmi\pmG\messiahStudio4.5...Filemode.dll -
0:000> !analyze -v
*******************************************************************************
*                                                         *
* Exception Analysis *
* *
*******************************************************************************

FAULTING_IP:
+0
00000000 ?? ???


EXCEPTION_RECORD: ffffffff -- (.exr ffffffffffffffff)
ExceptionAddress: 00000000
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 00000000
Parameter[1]: 00000000
Attempt to read from address 00000000

FAULTING_THREAD: 00000a60

PROCESS_NAME: maya.exe

OVERLAPPED_MODULE: AnimateMode

DEFAULT_BUCKET_ID: CORRUPT_MODULELIST_OVERLAPPED_MODULE


ERROR_CODE: (NTSTATUS) 0xc0000005 - L'istruzione a "0x%08lx" ha fatto riferimento alla memoria a "0x%08lx". La memoria non poteva essere "%s".

READ_ADDRESS: 00000000

BUGCHECK_STR: ACCESS_VIOLATION

THREAD_ATTRIBUTES:
LAST_CONTROL_TRANSFER:
LAST_CONTROL_TRANSFER: from 2a630ef3 to 00000000

STACK_TEXT:
0164973c 2a630ef3 2d875ff8 781c1bf8 7817775d 0x0
WARNING: Stack unwind information not available. Following frames may be wrong.
fffffffe 00000000 00000000 00000000 00000000 Filemode!InitFunction+0xf2d3

FAILED_INSTRUCTION_ADDRESS:
+0
00000000 ?? ???

FOLLOWUP_IP:
Filemode!InitFunction+f2d3
2a630ef3 8b0db4de7a2a mov ecx,[Filemode!MemSort+0x173084 (2a7adeb4)]

SYMBOL_STACK_INDEX: 1

FOLLOWUP_NAME: MachineOwner

SYMBOL_NAME: Filemode!InitFunction+f2d3

MODULE_NAME: Filemode

IMAGE_NAME: Filemode.dll

DEBUG_FLR_IMAGE_TIMESTAMP: 4b84579a

STACK_COMMAND: ~0s ; kb

FAILURE_BUCKET_ID: ACCESS_VIOLATION_BAD_IP_Filemode!InitFunction+f2d3

BUCKET_ID: ACCESS_VIOLATION_BAD_IP_Filemode!InitFunction+f2d3

Followup: MachineOwner

---------

The ACCESS_VIOLATION_BAD_IP is a bad instruction pointer, we're jumping from 2a630ef3 to an invalid memory address (00000000). We don't have debug symbols for Filemode.dll and we can't run Maya in debug mode on Windows.

I tried to compile the plugin for Alias Maya 6.5 (on the left) and obviously it works fine with Messiah 4.5. Now, without entering useless and boring debug details, the problem shouldn't be the plugin itself, because the only different thing here is Maya.

That's all for now, we'll see.

Best regards.