Notifications
Clear all

[Closed] [SDK] Storing Value pointer

Hello,

I’m trying to pass MAXScript objects to my C# assembly. I found out that all MAXScript objects are wrapped in a Value object. Currently the solution I have is: pass the MAXScript object to a C++ extension method, then return a pointer to the first element:
INT_PTR testAddress = (INT_PTR)&(*(arg_list[0]));

I then pass this address over to my C# assembly to marshal it back to a Value object. On that object I call the .To
method to get the right object out of the wrapper.

However, I was told it’s dangerous to store a Value pointer as its lifetime is controlled by MXS and it can be collected right after function execution. I should keep a pointer to the actual object the Value class is wrapping:
int integerValue = arg_list[0]->to_int();

I don’t understand how this would be done since I cannot get the address of integerValue because it’s just an unnamed stack object that will go out of scope after this function call.

Is it dangerous to hold a Value pointer? If so, how do I get a pointer to the actual value it’s wrapping? (Integers are just used as a test, I want to pass BitArrays, Point3’s,…)

valuePtr = GetMemoryAddress testValue --returns mem address of value wrapper object
memAddressWindow.MyTestMethod valuePtr --Marshal it back to Value object

Thanks,
Vin

2 Replies
 lo1

What would you do with a pointer of a value which is garbage collected? If you need persistent pointers to values, you’ll need to store the values yourself somewhere.

1 Reply
(@vincentt)
Joined: 11 months ago

Posts: 0

I see… so, for example, if I have a Value object that is wrapping around a node, the Value object can be collected even if the node is still referenced?

The problem with storing the pointers to the object the Value object is wrapping around is that I don’t know how to get them.

Point3 point3Value = arg_list[0]->to_point3();

This ‘point3Value’ variable would just be a local one on the stack, so getting his address is quite pointless (I think) as it’ll go out of scope soon. So how would I get the actuall address of the object it’s wrapped around?

Thanks