Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


- - - - -

asIScriptObject::Release return code


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
9 replies to this topic

#1 BlackMoons   Members   -  Reputation: 441

Like
0Likes
Like

Posted 25 September 2013 - 05:22 PM

Hi. Today I managed to accidentally access a null handle in a Angelscript destructor called by my C++ program calling asIScriptObject::Release() on a script class object passed from Angelscript to C++.

 

The problem? It never logged anything in my error logs.

I go and check Release()'s return code and its 0.

 

Shouldn't it be returning asEXECUTION_EXCEPTION? And then I could handle it the same way as when Context->Execute() hits a null handle?


Lead Coder/Game Designer for Brutal Nature: http://BrutalNature.com


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
0Likes
Like

Posted 25 September 2013 - 05:44 PM

asIScriptObject::Release returns the number of remaining references to the object. In your case it returned zero so you released the last one which destroyed the object.

You're not really meant to use the return value from Release or AddRef. These are only returned for debugging purposes.

You only need to know that after calling Release you should no longer access the object from that pointer.
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 BlackMoons   Members   -  Reputation: 441

Like
0Likes
Like

Posted 25 September 2013 - 06:36 PM

Ah, Then how should I detect when calling Release() results in a script exception and script execution of destructors being abandoned early?

 

I do understand that an exception in a destructor is a very bad thing that should be avoided at all costs due to potential for resource leaks, but that is exactly why I need to detect when it occurs so I can report the error and shut down the program so the code itself can be fixed.


Edited by BlackMoons, 25 September 2013 - 07:51 PM.

Lead Coder/Game Designer for Brutal Nature: http://BrutalNature.com


#4 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
0Likes
Like

Posted 26 September 2013 - 07:55 AM

That same question was asked a year ago, but unfortunately I haven't thought of an adequate solution to it yet.


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

#5 BlackMoons   Members   -  Reputation: 441

Like
0Likes
Like

Posted 28 September 2013 - 09:21 PM

On exception, Raise a bool flag in the context, Allow checking that bool and if true they can get info of the exception using the normal script exception mechanism.

 

Yea, its kinda ugly, But something has to be done to allow it.

 

It might also allow people to have a centralized cache in there main loop for angelscript errors encase they ever forget to check the return code of normal executes(), or some other process raises an unexpected exception.

 

It beats a callback in that you can at least handle the error where it occurred and have some state information if you just assert()/log to text file on it or similar.


Lead Coder/Game Designer for Brutal Nature: http://BrutalNature.com


#6 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
0Likes
Like

Posted 29 September 2013 - 10:28 AM

The problem is that the context that executes the destructor may not even be known by the application. If it is the garbage collector that calls it, then the garbage collector will create its own context for that execution.

 

I need to figure out a clean way of letting the application know about this internal context so that the application can set the exception callback, and even the line callback to allow the debugging of the destructor call.


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

#7 BlackMoons   Members   -  Reputation: 441

Like
0Likes
Like

Posted 30 September 2013 - 03:40 AM

Hold a ref to the last erroring context in the engine itself and have the bool in the engine?


Lead Coder/Game Designer for Brutal Nature: http://BrutalNature.com


#8 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
0Likes
Like

Posted 30 September 2013 - 10:31 AM

The way I'm thinking about solving it is by having the engine invoke a callback from the application whenever it needs a context to execute some script code internally. The application can then supply a context that has been set up with the appropriate callbacks for catching exceptions. Not only would the application be able to report exception in the destructor this way, but it would also be able to debug the execution, and better pool the contexts to improve performannce.

 

It would also work better in a multithreaded environment as you could potentially have multiple contexts in parallel.

 

Of course, the application callback would be optional and if not provided the engine would create the context on its own as it currently does.


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

#9 BlackMoons   Members   -  Reputation: 441

Like
0Likes
Like

Posted 01 October 2013 - 08:59 PM

Ah that would be nice. Yea I would prefer that angelscript just reuse the one context I have with push/pop state and minimize run time allocations.


Lead Coder/Game Designer for Brutal Nature: http://BrutalNature.com


#10 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
0Likes
Like

Posted 18 May 2014 - 06:48 PM

I've implemented the support for this in revision 1929. See the description in the other thread for a brief overview of how it works.


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.



PARTNERS