Sign in to follow this  
_orm_

Enhancement Suggestion - Lazy Primitive Initialization

Recommended Posts

This behavior of Angelscript just bit me yet again, only this time it caused Bullet to crap itself. I have a double as a member variable that determines how much thrust is applied to an entity. However, because I left this value uninitialized in the base class, at random times I received the "Overflow in AABB" error, with no way to consistently reproduce the problem. It was actually a complete fluke that I discovered the source of the issue. These sorts of problems are one of the reasons that we use scripting languages. Therefore, I would like to recommend that primitive datatypes in Angelscript be initialized with a default value of 0 to mitigate these issues.

Share this post


Link to post
Share on other sites
Having random behaviour due to uninitialized memory is definitely bad. I'll see what I can do about this.

However, I will not guarantee that uninitialized variables will always be cleared to 0 by default. This would require extensive changes and impact the performance quite a bit. Especially with loops, where the VM would have to repeatedly clear all memory on the stack for each iteration.

Share this post


Link to post
Share on other sites
[quote name='WitchLord' timestamp='1318171397' post='4870811']
Having random behaviour due to uninitialized memory is definitely bad. I'll see what I can do about this.

However, I will not guarantee that uninitialized variables will always be cleared to 0 by default. This would require extensive changes and impact the performance quite a bit. Especially with loops, where the VM would have to repeatedly clear all memory on the stack for each iteration.
[/quote]

Loops aren't as much of a problem as much as member and global variables are, because those are the ones we actually work with the most. And if it would take too much time only to have performance take a hit, then I guess we could actually take what we learn from C and initialize our variables in the first place.

Share this post


Link to post
Share on other sites
The problem is if AngelScript has to keep track of the scope of local variables to guarantee that all variables are zeroed as they come into scope (e.g. in loops).

However, one-time initialization as memory is allocated shouldn't cause a lot if impact, and also shouldn't be difficult to implement. It will also solve your main problem, i.e. random behaviour for execution due to uninitialized memory.

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