I’m developing a Rhino plugin and I’m using a multithreaded dll. The dll doesn’t manipulate rhino objects at all - once the objects are passed to the multithreaded part of it, it does its thing, and then passes them back. However, I’m getting a very consistent crash…has any of this come up before?
Which programming language? What multithreading model? Can you post the code? Have you tried simplifying the code to pinpoint the problem?
A consistent crash in my experience (using C# with RhinoCommon) is usually caused by a stack overflow due to infinite recursion or due to an access violation where protected memory is being accessed.
It sounds like you know that Rhino is not thread safe. When adding objects to Rhino, make sure you do so on the main application thread.
So, after some testing, it turns out that a part of the problem has to do with the use of System.Timer. For instance, I’d like to create an infinite loop:
and I’d like to be able to interact with Rhino while this is going on. I set up a callback with System.Timer which allowed me to run the simulation while interacting with the UI, but I started to get all sorts of crashes (Memory Access Violation). I suspect this is because I was creating Rhino objects out of the timer callback function, which was probably on a different thread.
Any thoughts on how to work around this?
You may have more luck with DispatcherTimer (System.Windows.DispatcherTimer). This timer was introduced with WPF and will put events on the Dispatcher queue for evaluation on the main (GUI) thread.
I haven’t tried this with putting objects in Rhino in the way you describe though.
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Tick += OnTimerTick;
private void OnTick()
// do stuff
// call timer.Stop() to stop firing tick events
Just tried it out - works much better. Thanks!
Ok, cool. Good to know that works with DispatcherTimer.