Sign in to follow this  
iram

returning a pointer

Recommended Posts

iram    122
i have srObject and srEntity classes both with AddRef and DecRef. but i realised the Object_shape can never be returned properly. also, it always fail if i register this way: (use @ instead of &) srEntity@ CreateEntity (srObject@ in, srString& in) r = e->RegisterObjectType("3DEngine", 0, 0); r = e->RegisterObjectMethod("3DEngine", "srObject@ Load3DS (string& in)", asMETHOD(3DEngine, LoadObject), asCALL_THISCALL); r = e->RegisterObjectMethod("3DEngine", "srEntity@ CreateEntity (srObject& in, srString& in)", asMETHOD(3DEngine, CreateEntity), asCALL_THISCALL); ------------------------------------------------------------- srObject@ Object_shape; srEntity@ Entity; @Object_shape = STAR.Load3DS ("train.3ds"); if (Object_shape == null) STARX.Util.LogS("train not found"); @Entity = STAR.CreateEntity (Object_shape, "TEST");

Share this post


Link to post
Share on other sites
WitchLord    4678
Iram,

when you're asking a question like this. Please try to imagine what we might need to answer your question. Simply stating that your program fails is not very useful. We need to know how and where the program fails. We also need to know what the error code is. And you're probably receiving an error message from the library as well (at least you would if you had set the message stream with SetCommonMessageStream before calling the registration functions).

If your srObject supports object handles, then there shouldn't be any problems with returning the object as a handle.

What is the C++ function signature for the 3DEngine::LoadObject and 3DEngine::CreateEntity?

Regards,
Andreas

Share this post


Link to post
Share on other sites
iram    122
oops...sorry missed those out.

Entity *CreateEntity (Object *object, const string& name);
Object *Load3DS (const string& filename);

these are external to my program, i got no control over them.

it failed at this line, "unable to write" pointer exception.
@Entity = STAR.CreateEntity (Object_shape, "TEST");

but it is returning something from the earlier line, not null since "train not found" is not displayed.

@Object_shape = STAR.Load3DS ("train.3ds");
if (Object_shape == null)
STARX.Util.LogS("train not found");

i have tried another way via wrapper methods but the result is the same.

wrapper for Load3DS is entered, but not for CreateEntity.
so it crashes when trying to pass the Object_shape.





[Edited by - iram on March 17, 2006 2:59:38 AM]

Share this post


Link to post
Share on other sites
WitchLord    4678
This is strange indeed.

Are the reference counter properly updated for the objects? It could be that the objects are being destroyed unintentionally if the reference counter reaches 0 before it's time.

Try implementing a function so that you can examine the value of the Object_shape in the debugger before it's passed to the CreateEntity method.

Also, since you do not have control over the CreateEntity() and Load3DS() you might have use for the autohandles (@+) that AngelScript uses. The autohandles let you register methods that normally don't update the reference counter for an object handle, as AngelScript will do that for you. For example: void func(obj@+) will make sure the reference is decreased when the function returns, and obj@+ func() will make sure the reference is increased after the function returns.

Regards,
Andreas

Share this post


Link to post
Share on other sites
iram    122

i have created a function to try to check the Object_Shape passed to the CreateEntity method.

this is weird because even if it is deleted, i should be able to see it becoming null. but the system crashes before reaching the method, never reached the breakpoint, so i cannot see what is the object value.

i will try to autohandles (@+)

Share this post


Link to post
Share on other sites
iram    122

not able to register with srObject@ in the parameter.
tried with srObject@+ with no valid.

in CPP:
Entity *CreateEntity (Object *object, const string& name);

r = e->RegisterObjectMethod("3DEngine", "srEntity@ CreateEntity (srObject@ in, srString& in)", asMETHOD(3DEngine, CreateEntity), asCALL_THISCALL);

both return -10.

i thought it should be fine but why invalid declaration ?

Share this post


Link to post
Share on other sites
WitchLord    4678
You need to remove the 'in' keyword when registering the @ parameter. This is a keyword that is only valid together with parameter references.

Are you setting the message stream before calling any of the register methods? The engine should have told you why it is an invalid declaration. Let me know if it didn't, so that I can correct it.

Regards,
Andreas

Share this post


Link to post
Share on other sites
iram    122

is it just these anywhere ?

CBufferedOutStream AngelOutput;
engine->SetCommonMessageStream(&AngelOutput);


i found out why the method crashes, it is due to @ with in.

it works now with the following registration:
srEntity@ CreateEntity (srObject@, srString& in)

thanks for the help!!!

Share this post


Link to post
Share on other sites
WitchLord    4678
Exactly. I recommend setting the message stream right after creating the engine. It has been designed so that if there are no errors, there will be no output, so even in production code there shouldn't be any problem with doing this.

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