Sunday, 21 October 2007

Debugging C# Rhino 4 plug-ins

Last week a colleague sent me a Rhino 4 plug-in, asking for help to debug it. Rhino-4 is a 3D graphics package which has become popular in universities. It has similar functionality to Alias Maya, 3DS Max etcetera, etcetera.

The easiest way to debug these rhino plug-ins, is to set the environment up so that starts Rhino (see graphic).

Then you can set break points, and if errors get raised you can step into them.

The error I found in the code was a consequence of C# array items not be instantiated. C# does not support dynamic arrays in the way for example that VBA and does.

The way the arrays were being declared was creating an array of whatever size, but was not populating that array with any actual objects.

Consequently I added a function that achieves the same thing to the end of the class, which I call to populate the array.

private whateverS[] GetArrayOfwhateverS(int num_whatever)
System.Collections.ArrayList al = new ArrayList();
whateverS whatever;
for(int i = 0; i < num_whatever + 1; i++) {
boid = new whateverS();
return (whateverS[])al.ToArray(typeof(whateverS));

There were 2 different functions referring to what ought to be the same array. So I made it a private class level variable to support that. I made the array a private class level variable so that it could be accessed throughout the class.