MaterialTableEvent Exception


#1

We are tracking some MaterialTableEvents and are seeing Exceptions even though we are not doing any code in the Event Handler.

Just wiring up this code we are observing an exception:

RhinoDoc.MaterialTableEvent += RhinoDoc_MaterialTableEvent;

System.NullReferenceException: Object reference not set to an instance of an object.

We have even emptied the code from our EventHandler and still observe this event.


(Steve Baer) #2

I can’t repeat this. Can you give me some steps to try? I’m guessing this exception must occur after you tweak something on a material, but I just can’t quite figure out what your tweak is.


#3

Sure.

It appears as though we get the Exception when using VRay as our Default Renderer. Then create a material using the VisMatEd command.

As soon as the material is created we get the Null Exception.

I forgot to mention, we are using the HostUtils.OnExceptionReport event to log all exceptions that occur within Matrix.

We are reaching out to Chaos Group, but if you have any insight that would be great.

Thanks,

Jake


(Steve Baer) #4

Do you get any line numbers or function location information in the exception?


#5

This screenshot is all the info I can gather.

It looks like it may be related to the Done() method.

I know this error seems to only occur when our plugin is running, so I am trying to isolate the materials or something that is triggering the error.


#6

Steve,

Here are the steps to reproduce the exception:

  1. Create an empty Rhino Plugin, then put this code in the constructor.

RhinoDoc.MaterialTableEvent += RhinoDoc_MaterialTableEvent;

  1. VRay’s VisMatEditor using VisMatEd command.
  2. Right Click Scene Materials in the list and choose Create Material > Standard
  3. Exception will happen.

Let me know if there is anything more you need.

Thanks for your help!

Jake


#7

After working with Travis Serio from GV we were able to duplicate the issue with out having VRayForRhino loaded.

All you need to do is have a run the code below:

 RhinoDoc.MaterialTableEvent += RhinoDoc_MaterialTableEvent;

 Material mat = new Material();
 mat.DiffuseColor = Color.Red;
 mat.AmbientColor = Color.Black;
 mat.SpecularColor = Color.White;
 int newMatIdx = RhinoDoc.ActiveDoc.Materials.Add(mat);

and add this function:

 private void RhinoDoc_MaterialTableEvent(object sender, MaterialTableEventArgs e)
 {
     RhinoApp.WriteLine("Material Table Event Fired");
 }

The exception is only shown if you add a delegate to the Rhino.Runtime.HostUtils.OnExceptionReport such as like this.

HostUtils.OnExceptionReport += HostUtils_OnExceptionReport;

private void HostUtils_OnExceptionReport(string source, Exception ex)
 {
      if (ex.InnerException == null)
      {
          RhinoApp.WriteLine(ex.Message);
      }
      else
      {
          RhinoApp.WriteLine(ex.InnerException.Message);
      }
  }

Please let me know if there is anything else I need to change in V-RayForRhino / Matrix in order to get this to work.


(Steve Baer) #8

Thanks Matt; I can’t repeat this at all. Which version of Rhino are you testing with?


#9

Rhino 5 x64 SR9 (6/9/2014)

I don’t know if this exception is causing any issues since it is caught and handled by RhinoCommon maybe Jason can add more information.


#10

Steve,

Here is a sample Plugin project which demonstrates the issue.

We too are using Rhino 5 SR9 64 bit.

MaterialTestPlugin.zip (23.0 KB)