Sign in to follow this  
Rakkar2

Simple object without AddRef

Recommended Posts

I have some non-virtual, shallow-copy safe classes that I cannot change, such as vectors and matrices. I want these to be instantiable objects which are automatically created when they are in-scope and deleted out of scope, without reference counting. I will never reference an object created in script from C++. For example: { // myVec should be created here! Vector3 myVec; myVec.x=0; // myVec should be deleted here! } The problem is, some of my functions return pointers to vectors. Which means I have to use references "@". At first I tried reference counting by adding a refCount via inheritance. But that only works for functions I control. Because when the function returns a pointer to the base class, and not to the derived class, the reference counter doesn't get instantiated. It's not an option to derive/change 200+ functions to return instances of my reference counted class. What I really need is just a reference/pointer to the true class, forget about reference counting. I already tried SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES,1) but it won't allow me to make a reference without first registering a function ADD_REF What can I do? [Edited by - Rakkar2 on May 8, 2007 8:13:12 PM]

Share this post


Link to post
Share on other sites
Your C++ registered functions should be able to return references to the vector3 objects, without the need for unsafe references or reference counting. Just register them as:

"vector3 &func()"

The script can then use the returned reference on the left side of assignment expressions, if that is what you need.

Of course, you'll have to make sure the pointer returned from the function is never null, as that would crash the application.

Functions declared in scripts are not allowed to return references to these types though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this