Mogre 1.7.1 with VS2010 HardBuffManager.Singleton missing?

AliAkdurak

10-06-2010 14:15:09

Hello everyone

I tried to run the Meshbuilder class from tutorials today with mogre 1.7.1 and Vs2010 binaries but unfortunately I cannot reach the Hardwarebuffermanager.singleton property. Does anybody have idea why this may happened, if it's an simple syntax error where the guy(See note) created 2010 binaries did create them before gantz solved the hardwarebuffermanager problem, I may try go to the repo and fix it I was thinking of getting involed anyway.

Thanks upfront :D.

Ali Akdurak
Sİmulation R&D Lead Computer Engineer
Teksav Teknoloji
Web: http://www.teksav-teknoloji.com

Note: Thank you a lot! I am sorry I forgot your name :oops: you really helped me 2 weeks ago.
Note 2: Also we are looking for fulltime engineers and will recruit 2 interns and 2 senior/junior engineers who has knowledge and/or interest in OGRE(Works with mogre)(In Izmir/Turkey || İzmir/Türkiye). I was going to put a post in here and ogre forums but cant be sure if its okay or not. If it's ok please pm me :) if its not ok to write such note I will also remove this line

this is the code where hardwarebuffermanager.singletons flash up as that property cannot be found.

/// <summary>
/// A helper class for manual mesh
/// This class hide unsafe code
/// This code is based on MeshBuilderHelper.h
/// originally developed by rastaman 11/16/2005
/// </summary>
public class MeshBuilderHelper
{
public MeshBuilderHelper(String name, String resourcegroup,
bool usesharedvertices, uint vertexstart, uint vertexcount)
{
mName = name;
mResourceGroup = resourcegroup;
mVertextStart = vertexstart;
mVertexCount = vertexcount;

// Return now if already exists
if (MeshManager.Singleton.ResourceExists(name))
return;

mMeshPtr = MeshManager.Singleton.CreateManual(mName, mResourceGroup);
mSubMesh = mMeshPtr.CreateSubMesh();
mSubMesh.useSharedVertices = usesharedvertices;
mSubMesh.vertexData = new VertexData();
mSubMesh.vertexData.vertexStart = mVertextStart;
mSubMesh.vertexData.vertexCount = mVertexCount;
offset = 0;
mIndexType = HardwareIndexBuffer.IndexType.IT_16BIT;
}


public virtual VertexElement AddElement(VertexElementType theType,
VertexElementSemantic semantic)
{
VertexElement ve = mSubMesh.vertexData.vertexDeclaration.AddElement(0, offset,
theType, semantic);
offset += VertexElement.GetTypeSize(theType);
return ve;
}

public virtual void CreateVertexBuffer(uint numVerts, HardwareBuffer.Usage usage)
{
CreateVertexBuffer(numVerts, usage, false);
}

public virtual void CreateVertexBuffer(uint numVerts,
HardwareBuffer.Usage usage,
bool useShadowBuffer)
{
mVertexSize = offset;
mNumVerts = numVerts;

mvbuf = [u]HardwareBufferManager.Singleton[/u].CreateVertexBuffer(
mVertexSize, mNumVerts, usage, useShadowBuffer);
unsafe
{
pVBuffStart = mvbuf.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
}
}

public virtual void SetVertFloat(uint vertexindex, uint byteoffset, float val1)
{
if (vertexindex >= mNumVerts)
throw new IndexOutOfRangeException(
"'vertexIndex' cannot be greater than the number of vertices.");
unsafe
{
byte* pp = (byte*)pVBuffStart;
pp += (mVertexSize * vertexindex) + byteoffset;
float* p = (float*)pp;
*p = val1;
}
}

public virtual void SetVertFloat(uint vertexindex,
uint byteoffset,
float val1,
float val2)
{
if (vertexindex >= mNumVerts)
throw new IndexOutOfRangeException(
"'vertexIndex' cannot be greater than the number of vertices.");
unsafe
{
byte* pp = (byte*)pVBuffStart;
pp += (mVertexSize * vertexindex) + byteoffset;
float* p = (float*)pp;
*p++ = val1;
*p = val2;
}
}

public virtual void SetVertFloat(uint vertexindex,
uint byteoffset,
float val1,
float val2,
float val3)
{
if (vertexindex >= mNumVerts)
throw new IndexOutOfRangeException(
"'vertexIndex' cannot be greater than the number of vertices.");
unsafe
{
byte* pp = (byte*)pVBuffStart;
pp += (mVertexSize * vertexindex) + byteoffset;
float* p = (float*)pp;
*p++ = val1;
*p++ = val2;
*p = val3;
}
}

public virtual void SetVertFloat(uint vertexindex,
uint byteoffset,
float val1, float val2, float val3, float val4)
{
if (vertexindex >= mNumVerts)
throw new IndexOutOfRangeException(
"'vertexIndex' cannot be greater than the number of vertices.");
unsafe
{
byte* pp = (byte*)pVBuffStart;
pp += (mVertexSize * vertexindex) + byteoffset;
float* p = (float*)pp;
*p++ = val1;
*p++ = val2;
*p++ = val3;
*p = val4;
}
}


public virtual void CreateIndexBuffer(uint triaglecount,
HardwareIndexBuffer.IndexType itype,
HardwareBuffer.Usage usage)
{
CreateIndexBuffer(triaglecount, itype, usage, false);
}

public virtual void CreateIndexBuffer(uint triaglecount,
HardwareIndexBuffer.IndexType itype,
HardwareBuffer.Usage usage,
bool useShadowBuffer)
{
mvbuf.Unlock();
mTriagleCount = triaglecount;
mIndexType = itype;
mSubMesh.vertexData.vertexBufferBinding.SetBinding(0, mvbuf);
mSubMesh.indexData.indexCount = mTriagleCount * 3;
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager.Singleton
.CreateIndexBuffer(mIndexType, mTriagleCount * 3, usage, useShadowBuffer);
mSubMesh.indexData.indexBuffer = ibuf;
unsafe
{
pIBuffStart = ibuf.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
}
}

public virtual void SetIndex16bit(uint triagleIdx,
ushort vidx1, ushort vidx2, ushort vidx3)
{
if (triagleIdx >= mTriagleCount)
throw new IndexOutOfRangeException(
"'triagleIdx' cannot be greater than the number of triangles.");
if (mIndexType != HardwareIndexBuffer.IndexType.IT_16BIT)
throw new NotSupportedException(
"HardwareIndexBuffer.IndexType other than 'IT_16BIT' is not supported.");
unsafe
{
ushort* p = (ushort*)pIBuffStart;
p += (triagleIdx * 3);
*p++ = vidx1;
*p++ = vidx2;
*p = vidx3;
}
}

public virtual void SetIndex32bit(uint triagleIdx,
uint vidx1, uint vidx2, uint vidx3)
{
if (triagleIdx >= mTriagleCount)
throw new IndexOutOfRangeException(
"'triagleIdx' cannot be greater than the number of triangles.");
if (mIndexType != HardwareIndexBuffer.IndexType.IT_16BIT)
throw new NotSupportedException(
"HardwareIndexBuffer.IndexType other than 'IT_16BIT' is not supported.");
unsafe
{

uint* p = (uint*)pIBuffStart;
p += (triagleIdx * 3);
*p++ = vidx1;
*p++ = vidx2;
*p = vidx3;
}
}
public virtual MeshPtr Load(String materialname)
{
mSubMesh.indexData.indexBuffer.Unlock();
mSubMesh.SetMaterialName(materialname);
mMeshPtr.Load();
return mMeshPtr;
}

#region Protected and Private fields
protected MeshPtr mMeshPtr;
protected SubMesh mSubMesh;
protected String mName, mResourceGroup;
protected uint mVertextStart, mVertexCount;
protected HardwareVertexBufferSharedPtr mvbuf;
protected uint offset;
protected uint mVertexSize;
protected uint mNumVerts;
protected unsafe void* pVBuffStart = (void*)0;
protected uint mTriagleCount;
protected HardwareIndexBuffer.IndexType mIndexType;
protected unsafe void* pIBuffStart = (void*)0;


#endregion

}

mstoyke

10-06-2010 14:34:11

I'm quite busy this week and don't have much time left that I could spend on Mogre right now. If you need a quick solution, just get the sourcecode from my repositories at bitbucket:

http://bitbucket.org/mstoyke

These sources are exactly what I used to compile the binaries. Maybe you will be able to fix it there. The sourcecode should already contain the fixes, because it was pulled from Gantz' repository after he announced the hardware buffer fix. But obviously some people tried it and it did not work, so I might have broken something by converting the project to VS2010.

I will definitely look into the issue later, but it can take 1-2 weeks before I can work on it.

AliAkdurak

10-06-2010 14:52:05

Ok then I will try to ease your burden a little. I am getting your source code , gonna build and check if the issues is there. I will post a report when I am done. Thank you for the quick response and for the VS2010 binaries.

AliAkdurak

11-06-2010 10:58:33

I am trying to build the system but I keep getting this error when I try to patch with mercurial. AnyIdea how I may solve this

applying C:\Users\G------\Documents\Projeler\MogreMyStoke\Main\Ogre Patches\Mogre.patch
unable to strip away 1 dirs from CMakeLists.txt
abort: patch failed to apply

[command interrupted]

mstoyke

13-06-2010 08:14:08

If you use the Ogre version that I keep in the bitbucket repository, update to the branch named "MST". All needed patches are already applied to the source in this branch and you can just compile it from the provided VS solution and use it to compile Mogre. Also use the branch "MST" in my Mogre repository. Sorry that I forgot to mention that before.

AliAkdurak

15-06-2010 12:17:44

Well the autowrapper show the unmanaged C++/CLI code that it generates clearly a public property of Hardwarebuffermanager singleton. I am not sure why it doesnt show in the dll declaration. I will continue with my build effort than report if I found something more.

private protected:
static HardwareBufferManager^ _singleton;
Ogre::HardwareBufferManager* _native;
bool _createdByCLR;

//Internal Declarations
public protected:
HardwareBufferManager( Ogre::HardwareBufferManager* obj ) : _native(obj)
{
}


//Public Declarations
public:

static property HardwareBufferManager^ Singleton
{
HardwareBufferManager^ get()
{
Ogre::HardwareBufferManager* ptr = Ogre::HardwareBufferManager::getSingletonPtr();
if (_singleton == CLR_NULL || _singleton->_native != ptr)
{
if (_singleton != CLR_NULL)
{
_singleton->_native = 0;
_singleton = nullptr;
}
if ( ptr ) _singleton = gcnew HardwareBufferManager( ptr );
}
return _singleton;
}
}

AliAkdurak

15-06-2010 14:37:41

Well I am stuck with a compile error at Ogre with #include "ClrObjects.inc" line where it say it cant find the source file. I will try to solve but help is much appreciated.

#define CLROBJECT(T) \
void _OgreExport __Init_CLRObject_##T(CLRObject *pObj);
#include "CLRObjects.inc"
#undef CLROBJECT

mstoyke

18-06-2010 19:29:51

If you can find some time to try it, here:

Mogre 1.7.1 VS2010 / .NET4 binaries HardwareBuffer Singleton Bugfix

...are some compiled binaries to replace some of the files in my last binary package. It's new versions of Mogre.dll and should contain the singleton property now. I just compiled this and could not test it at all, so it may do anything from crashing, eating all your cake to just work as expected. I would appreciate some feedback that would help me to make a new binary release soon.

Edit: file is now obsolete, newer binaries are available

peterjs2011

12-10-2010 08:11:07

hi mstoyke,
I am using Visual Studio 2010 and the .NET framework version 4.0, compiled binaries

when i use below code:

Ogre::HardwareVertexBufferSharedPtr vbuf =

Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(

mRenderOp.vertexData->vertexDeclaration->getVertexSize(0),

vertexBufferCapacity_,

Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,

false);

The messagebox show me: Attempted to read or write protected memory.This is often an indication that other memory is corrupt. And
In Ogre.log, the message is:OGRE EXCEPTION(5:ItemIdentityException): No buffer is bound to that index. in VertexBufferBinding::getBuffer at ..\..\ogre\OgreMain\src\OgreHardwareVertexBuffer.cpp (line 635)

When I call CreateIndexBuffer(), the same error happens.

Can you give me some suggestion?

thanks
peter

cricket

13-10-2010 17:36:07

hi mstoyke,
The problem is still exist, please cheak for it.
Thanks!

AliAkdurak

14-12-2010 12:38:56

I am positive that it is solved. Which binaries are you using ? are they the latest from the post in mogre 1.7.1 with Physx SlimDx MyGUI. If problem still persists how do you understand it? is it exactly the same with mine?