Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now
- - - - -

Any sample for callbacks ?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 Meyer   Members   

120
Like
0Likes
Like

Posted 26 September 2013 - 09:10 AM

Hi,

Do you have any sample explaning callbacks and funcdefs?

Because I tried and still have crashes :-(

 

I try to register a callback with 

r = engine->RegisterFuncdef("void OnCompleteHandler()");

 

and then a property with 

 

r = engine->RegisterObjectProperty("Test", "OnCompleteHandler @onComplete", asOFFSET(Test, onCompleteHandler)); 

 

In my Test class I have a property declared this way : 

 

asIScriptFunction *onCompleteHandler;

 

In my script I have a function

 

void MyCompleteHandler()
{
Log("Done");
};
 
but when this line is executed
 
@myTest.onComplete = @MyCompleteHandler; //<- crash when i try to set my property with my function handle.
 
I always crash in asCScriptEngine::CallObjectMethod because it tries to execute a release method on a object that doesn't exists.
 
Any help appreciated.
 
Thanks in advance
 
 
 


#2 Andreas Jonsson   Moderators   

4629
Like
0Likes
Like

Posted 26 September 2013 - 12:48 PM

Did you set onCompleteHandler = null in the constructor for your Test class?

 

If the pointer has any other value than null, i.e. 0, then the handle assignment will attempt to call Release on the pointer before updating it with the new handle.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Meyer   Members   

120
Like
0Likes
Like

Posted 27 September 2013 - 02:57 AM

Thx a lot ! You were right.

Now even if everybody knows my dirty secret ( I'm a bad programmer who forget to initialize variables ;-) ) I'm happy because I got callbacks with a generic (ref handle) userdata argument.

It works great !!!



#4 Meyer   Members   

120
Like
0Likes
Like

Posted 14 October 2013 - 07:27 AM

Hi again,

 

I tried to set my onCompleteHandler pointing to a class method but it doesn't work  (error : invalid opration on method)

in the script i tried : @test.onCompleteHandler= @myObject.myMethod; (where myObject is a class instance)

any idea ?



#5 Meyer   Members   

120
Like
0Likes
Like

Posted 14 October 2013 - 07:30 AM

Sorry , it works now, I just had to cast it like in the example

 @test.onCompleteHandler= OnCompleteHandler(myObject.myMethod);



#6 Andreas Jonsson   Moderators   

4629
Like
0Likes
Like

Posted 14 October 2013 - 09:00 AM

This is because for class methods you need to instanciate a delegate object to hold the object pointer together with the method pointer. The delegate object will then be treated as if it was a global function pointer and do the necessary translation to the class method when invoked.

 

Regards,

Andreas


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.