stack question

Monkey Forums/Monkey Programming/stack question

silentshark(Posted 2012) [#1]
Just trying to debug some of my code..

one line is confusing me. I'm using "Push" to create a new sprite object - here's the code - bullets.Push New Bullet_Sprite

This works fine most of the time.

This afternoon, though, I got an "Array index out of range" error on this line? Any thoughts, guys?

(have seen the error in HTML5 and Flash)


muddy_shoes(Posted 2012) [#2]
The stack code resizes if a push exceeds the existing size of the backing array so that should be fine. Are you accessing an array in your Bullet_Sprite constructor?


silentshark(Posted 2012) [#3]
Thanks very much for the pointer - yes, I am accessing an array in the constructor.

Presumably your thinking is that this is where the out of bounds occurs? I've looked at the code and can't see how this could be the case. Unless..

This makes me think of a related question.

This issue is happening in OnUpdate(). Now if I specify that I want 60 updates per second (using SetUpdateRate), Monkey will try to call OnUpdate 60 times per second. Is this guaranteed? What if too much is going on? At that point what happens to the execution path? Can Monkey be half way through your OnUpdate function then think to itself "times up, I'd better call OnUpdate again.." (hope I've explained this ok). If so, I can see how this might be causing me issues.


muddy_shoes(Posted 2012) [#4]
Presumably your thinking is that this is where the out of bounds occurs?

My thinking is only that you have an out of bounds error that must be happening somewhere. If the stack push method is okay then that somewhere is somewhere else. As you haven't posted any code I can't make any specific judgements about where that is.

Monkey will try to call OnUpdate 60 times per second. Is this guaranteed?

No, the update rate is not guaranteed.

Can Monkey be half way through your OnUpdate function then think to itself "times up, I'd better call OnUpdate again.."

Your update method won't be interrupted if it exceeds the requested update interval.


Samah(Posted 2012) [#5]
Can Monkey be half way through your OnUpdate function then think to itself "times up, I'd better call OnUpdate again.."

No, because Monkey is not multithreaded (unless you use my threading module).


silentshark(Posted 2012) [#6]
cheers for the response re OnUpdate.

I think I figured the problem - I had a logic error where I was calling the Remove method too many times. Reminds me of the old "double free" errors in C. My conjecture is that this was screwing things up on the stack big time.