VertexElement trouble


27-10-2006 10:28:47

Hi, I am currently working on a mesh viewer application using Mogre. Everything has been working great so far, but I recently ran into a strange problem. The VertexElement object seems to be behaving wierd.

Heres some very simple code that exposes the problem:

Mogre.VertexElement verElem = null;
if (verElem == null)
Console.WriteLine("Oh, I wish this worked!");

I believe the above code should work, but it throws the exception below on the line "if (verElem == null)".

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
at Mogre.VertexElement.op_Equality(VertexElement lhs, VertexElement rhs)
at LEXIView.MainForm..ctor(String sOpenFileName) in D:\ITE5000\Tools\LEXIView\LEXIView\MainForm.cs:line 52
at LEXIView.Program.Main(String[] args) in D:\ITE5000\Tools\LEXIView\LEXIView\Program.cs:line 21
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Any ideas?

Keep up the good work with Mogre!


27-10-2006 11:21:10

VertexElement overrides operator == but doesn't check for null parameters.

I'll fix it promptly, good catch!


27-10-2006 11:51:51

Excellent, thanks much! :)


27-10-2006 11:52:41

In the meantime, do a
Mogre.VertexElement verElem = null;
if ((object)verElem == null)

To avoid the exception.


27-10-2006 12:05:32

Thanks again!

Casting it to object works, cant believe I didn't think of that :)

I have another problem now though, it might be related.

Mogre.VertexElement verElem = curEntity.GetMesh().sharedVertexData.vertexDeclaration.FindElementBySemantic(Mogre.VertexElementSemantic.VES_DIFFUSE);

Throws the same exception as before. I think it does that when the element can't be found.


27-10-2006 16:06:09

You're right, throws an exception instead of returning null, that's another bug of VertexElement; I fixed it on SVN.

But there's no easy workaround for this, you have to catch the exception at the moment. :?