Wrapping OgreMaxSceneLoader

idcsteve

24-08-2012 16:09:49

Hi all,

I'm stepping way outside my comfort zone and trying to wrap the ogremax scene loader. My primary goal is to get it to work without losing the will to live.
I've successfully compiled Mogre in x64, and it's all been lovely. I've wrapped libraries before, so I thought I'd give this a crack. Not a good plan!

My current problem is an error message that says
Error 1 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c00000a). C:\Users\VTime\Documents\Visual Studio 2010\Projects\VTimeGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper

Plus a whole lot more of those. Using ildasm, I've found that this particular error refers to CustomAttribute2 of Ogre::Radian. The other errors refer to other structures, like Ogre::Degree. The exact text in the output is:

CustomAttribute #2 (0c00000a)
// -------------------------------------------------------
// CustomAttribute Type: 0a000002
// CustomAttributeName: System.CLSCompliantAttribute :: instance void .ctor(bool)
// Length: 5
// Value : 01 00 00 00 00 > <
// ctor args: ( <can not decode> )


Has anyone who knows more than me about how Mogre talks to c++ (i.e. most of you, and probably my cat too) seen something like this and, if so, do you know how to fix it?

I got this far by:
Compiling TinyXML with stl in release 64 with /MD
Creating a Clr Class Library project called OgreMaxWrapper
Copying the files recommended by the Ogremax documentation (http://www.ogremax.com/Documents/OgreMa ... -code.html) to my project
Referencing the Ogre include directories
Referencing the Mogre include directories and Mogre.lib (I tried linking to OgreMain.lib instead, with exactly the same result, right down to the hex in the error codes).
Using the following simple file, the credit (or blame) for which comes from viewtopic.php?f=8&t=13711 and looking at how mogre does wrapping internally.


#pragma once
#include "Stdafx.h"
#include "MogreStableHeaders.h"
#include "OgreMaxScene.hpp"
using namespace System;
namespace OgreMaxWrapper {

public ref class Scene
{
OgreMax::OgreMaxScene* _scene;
public:
Scene()
{
_scene = new OgreMax::OgreMaxScene();
}

void Load
(String^ fileNameOrContent,
Mogre::RenderWindow^ renderWindow)
{
}

};
}


I can provide any other details you might need on this, but I'm not sure what could be relevant.

Any suggestions welcome!
Thanks for getting this far,
Steve

P.S. There are 100 metadata errors. Here's a sample:

Error 101 error LNK1255: link failed because of metadata errors C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\LINK OgreMaxWrapper
Error 1 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c00000a). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 2 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c00000e). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 3 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c000012). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 4 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c000016). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 5 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c00001a). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 6 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c000021). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 7 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c000023). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 8 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c000028). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 9 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c00002f). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 10 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c000037). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper
Error 11 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c000056). C:\Users\User\Documents\Visual Studio 2010\Projects\UserGame\OgreMaxWrapper\OgreMaxWrapper.obj OgreMaxWrapper

Zonder

27-08-2012 10:04:21

did you try turning this to false CLSCompliantAttribute I have never done this before my self but surly the projet won't be CLS compliant

http://msdn.microsoft.com/en-us/library/bhc3fa7f.aspx

just made a clr c++ project to have a look it does turn CLSCompliant on as default turn it off in AssemblyInfo.cpp

idcsteve

28-08-2012 10:59:43

Hi Zonder,

Thanks, but unfortunately that didn't work. I'd really like to get this to work without having to port it all to C#.

Any other ideas? I'll try anything :)
[Edit] I've also checked that I'm using /clr not /clr:pure
Regards,
Steve

Zonder

28-08-2012 11:29:53

Which include causes the error to start happening?
Can you see what custom attribute 2 is?

maybe one of those will help identify the issue.

Also not sure if you saw on the wiki a simple wrapping to particle universe

http://www.ogre3d.org/tikiwiki/tiki-ind ... e=PUDotNet

Zonder

28-08-2012 11:31:44

oh just read something you are targeting the correct framework to what mogre / ogre was compiled in arn't you?

idcsteve

29-08-2012 10:38:22

Hi Zonder,

Thanks for the example. If I can get this to work, I'll post something similar.

Mogre and my wrapper are both referencing ,NET 4.0. I'm not sure how to figure out what the version is for Ogre, since it's not CLR.

[Edit]
The inclusion of MogreStableHeaders.h seems to be the problem. I'm going to have a look at the example you linked to and see if I'm doing anything wrong.


#pragma once
#include "Stdafx.h"
#include "MogreStableHeaders.h"//Commenting this line makes the errors go away
#include "OgreMaxScene.hpp"
using namespace System;
namespace OgreMaxWrapper {

public ref class Scene
{
public:
Scene()
{
}
};
}


I've never worked with a disassembler before, so I have no idea what this means, but I'm including the whole Radian disassembly for completeness:
// TypeDef #8 (02000009)
// -------------------------------------------------------
// TypDefName: Ogre.Radian (02000009)
// Flags : [Public] [SequentialLayout] [Class] [Sealed] [AnsiClass] [BeforeFieldInit] (00100109)
// Extends : 0100000C [TypeRef] System.ValueType
// Layout : Packing:0, Size:4
// Field #1 (04000067)
// -------------------------------------------------------
// Field Name: <alignment member> (04000067)
// Flags : [Private] (00000001)
// CallCnvntn: [FIELD]
// Field type: R4
// Offset : 0xffffffff
//
// CustomAttribute #1 (0c000009)
// -------------------------------------------------------
// CustomAttribute Type: 0a000004
// CustomAttributeName: System.Runtime.CompilerServices.NativeCppClassAttribute :: instance void .ctor()
// Length: 4
// Value : 01 00 00 00 > <
// ctor args: ()
//
// CustomAttribute #2 (0c00000a)
// -------------------------------------------------------
// CustomAttribute Type: 0a000002
// CustomAttributeName: System.CLSCompliantAttribute :: instance void .ctor(bool)
// Length: 5
// Value : 01 00 00 00 00 > <
// ctor args: ( <can not decode> )
//
// CustomAttribute #3 (0c00000b)
// -------------------------------------------------------
// CustomAttribute Type: 0a000003
// CustomAttributeName: Microsoft.VisualC.MiscellaneousBitsAttribute :: instance void .ctor(int32)
// Length: 8
// Value : 01 00 40 00 00 00 00 00 > @ <
// ctor args: (64)
//
// CustomAttribute #4 (0c00000c)
// -------------------------------------------------------
// CustomAttribute Type: 0a000001
// CustomAttributeName: Microsoft.VisualC.DebugInfoInPDBAttribute :: instance void .ctor()
// Length: 4
// Value : 01 00 00 00 > <
// ctor args: ()


I'm guessing that the "Cannot decode" in attribute 2's constructor is the problem, but that's about my limit.
Thanks for your help so far,
Steve

Zonder

29-08-2012 11:18:05

try commenting out CLSCompliantAttribute line in assemblyinfo since that's attribute 2

Zonder

29-08-2012 11:20:53

maybe you should be including Ogre.h not MogreStableHeaders.h

idcsteve

29-08-2012 12:58:56

Hi Zonder,

Thanks for the quick reply.

Commenting the CLSCompliantAttribute line didn't work, unfortunately.

If I reference Ogre.h then when I try:
void Load
(String^ fileNameOrContent,
Mogre::RenderWindow^ renderWindow)
{

}


I get the following compiler errors, related to being unable to find Mogre:


Error 40 error C2061: syntax error : identifier 'RenderWindow' c:\users\vtime\documents\visual studio 2010\projects\vtimegame\ogremaxwrapper\OgreMaxWrapper.h 21 1 OgreMaxWrapper
Error 39 error C2653: 'Mogre' : is not a class or namespace name c:\users\vtime\documents\visual studio 2010\projects\vtimegame\ogremaxwrapper\OgreMaxWrapper.h 21 1 OgreMaxWrapper


I'll pick up a copy of particle universe and see if I can get it to work, but this line from the wiki page worries me.
For compilation of the wrapper it's needed to link against the Mogre version of the Ogre libraries when building PU, otherwise it will not work. (means: The Ogre sources, which are modified specific for Mogre)

I followed the instructions for compiling the x64 version of Mogre found here http://www.ogre3d.org/tikiwiki/How+to+c ... 64+systems, but the only change I made to the Ogre sources were to define LINK_TO_MOGRE and to apply the patch. I'm hoping that was enough.

Many thanks,
Steve

Zonder

29-08-2012 13:21:53

You need to add an assembly reference to Mogre maybe (right click project file and references)

But the other issue might be a problem as you aren't building the scene loader against OgreMain from Mogre.

I don't know enough about how c++ dlls bind to each other but it would need to be the same version of ogre and using the same version compiler. Also not sure if the mogre linking effects the exports that's easy to check with dependancy walker though with the SDK version and the Mogre one (I can't do this atm at work)

idcsteve

29-08-2012 16:31:14

You need to add an assembly reference to Mogre maybe (right click project file and references)

That did it. Zonder, you are officially awesome. Thanks for taking the time to help.
Regards,
Steve

Zonder

29-08-2012 18:20:17

Great! and it's no prob

It gives me some tips for wrapping as well never done it my self like I said :)

Lets hope the scene loader works with the mogre version of ogremain now :?

idcsteve

29-08-2012 20:26:17

The wrapping is working and I'm able to load and animate a scene. I'll set up a wiki entry with step-by-step info once I'm done.

Zonder

30-08-2012 09:37:54

so the precompiled ogremax is working with the ogre you compiled?

if so maybe that new particle system can get wrapped for mogre http://ogre3d.org/forums/viewtopic.php?f=11&t=70299 (only 32bit though :( ). I also would love to see noesis gui get over, I am going to have a look already got on beta http://ogre3d.org/forums/viewtopic.php?f=4&t=68930 it such an obvious library to have available in mogre been xaml based :)