User Data & Dispose

Hi all.
I have some problems with user data and i looked at one post of Menno (Std::__non_rtti_object unhandled exception followed by crash) and it seems the same situation. He told that he solved it by moving the dispose code out of the threaded part of the code, but i did not undestand how to manage it.
@menno
@stevebaer

By debugging I have seen that there is an " out of range exception " in try catch block when trying to add user data to attirbutes. This happens only sometimes and i can’t understand why.
1)It enters first " CurrentDomain_FirstChanceException" as Menno saw.
AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
static void CurrentDomain_FirstChanceException ( object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
{var mess=e.Exception.Message;//index out of range}
1)i have this class: easy_PhysicalData : Rhino.DocObjects.Custom.UserData
2)it enters "catch"during iteration like the following one :
for(int i=0;i<items.Count;i++)
{
try
{
var ud=new easy_PhysicalData ();
var my_attributes = new Rhino.DocObjects.ObjectAttributes();
my_attributes.UserData.Add(ud);//while debugging in this line the code enters “catch”
}
catch(Exception e)
{
var message=e.Message;
}
}

Rhino is not thread safe. Are you trying to add user data to document objects?

thank you for replay. i did not try to add only, i really added user datat to document objects attributes with fine results in combination wirh rhyno history. now i was thinking to use "lock " when calling new attributes and adding user data in iteration but i don t know if it works . At the same time i did not understand well menno solution.

thank you for replay. i did not try to add only, i really added them with fine results in combination wirh rhyno history. now i was thinking to use "lock " when calling new attributes and adding user data in iteration but i don t know if it works . At the same time i did not understand well menno solution.

I’ve been trying to look into my code from Aug '14 where this problem was, but I can’t seem to pinpoint the problem anymore. Sorry :blush:

thank you Menno any case. do you have any suggestion to manage not thread safe code? I have problem when adding user data to new attribute object in " for" iteration. now i will try to lock this object but i can’t understand if it can be a solution because it is a new object inside iteration , so what “lock” instrution can do?probably the problem is the garbage collector …i don t know how to solve it but all my project is based on it because it is very very usefull in combination with history. i like it very much…until it crashes. i only know that it crashes into overtide method “dispose” of user data

Yes Dale. i would like to understand what is the problem of user data.

Hi Aurelio,

There is not enough information here for us to be of any help. Can you create and provide a simple plug-in project that repeats the problem? Also, being that Rhino is not thread safe, if you run your code in the main thread, do you will have the “issue?”

– Dale