Index out of range on tick plus speed prob.

enonod

Well-Known Member
Licensed User
Longtime User
Sorry to be asking so many questions but after attempting to find the solution I see no alternative.
The attached code illustrates my two problems.
1. Line 53 error index out of bounds I find baffling. Removing line 73 removes the error but of course the result is incorrect.

2. The AddSprites sub has slowed the action by say, 50%. The sprites are static and although of course repainted, I cannot see that it is likely to be the cause.
Removing line 50 recovers the speed.
Any help appreciated.
 

agraham

Expert
Licensed User
Longtime User
Your Pawns have six frames which means CurrentFrame can be between 0 and 5. You are setting Pawn.Data, and hence CurrentFrame, to values higher than 5 which means Tick is trying to access non-existent frames.

Your Timer interval is unrealistic at 1mS. Tick probably takes longer than this to run with 40 Sprites so the update speed is dependant on the number of Sprites being drawn. A value between, say, 20 and 60 would be more appropriate.
 

enonod

Well-Known Member
Licensed User
Longtime User
Thanks and sorry. I was blinded by the Mod 3 and ignored the shifting bit.
1ms is now obvious as too short a time, however the sub is actually part of the main app and only called once, therefore apart from repaint nothing should be happening. Changing the interval to anything upwards (to 100) makes no difference except to get slower. So I still can't see the reason for the speed cut.
 
Last edited:
Top