Jump to content
  • Advertisement
Sign in to follow this  
iram

returning a pointer

This topic is 4505 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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

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

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
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

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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!