46
Solved Bugs / Aim getting WAAAAAY too big
« on: October 27, 2005, 03:12:25 PM »
I found a new one.
A really frickin stupid one too.
It should never exist. Whoever programmed this bit of code should change his name to Richard Head.
It was quite possibly me that did it :redface:
Here is the code
The error occurs on line
Holding the mouse over ".mem(aimsx)" gives -32000
Holding the mouse over ".mem(aimdx)" gives 1256
This is obviously going to push .aim beyond the 32768 limit and give us an overflow.
I thought I had fixed this ages ago by limiting .aim to a magnitude of 1256. The code to do it is right up there in this chunk of code.
See if you can spot the stupid ass mistake in it.
A really frickin stupid one too.
It should never exist. Whoever programmed this bit of code should change his name to Richard Head.
It was quite possibly me that did it :redface:
Here is the code
Code: [Select]
If Abs(.mem(aimsx) > 1256) Then .mem(aimsx) = 1256 * Sgn(.mem(aimsx)) 'new crash fix?
If Abs(.mem(aimdx) > 1256) Then .mem(aimdx) = 1256 * Sgn(.mem(aimdx))
If .mem(setaim) <> 32000 Then
While .mem(setaim) > 1256
.mem(setaim) = .mem(setaim) - 1256
Wend
While .mem(setaim) < 0
.mem(setaim) = .mem(setaim) + 1256
Wend
.aim = .mem(setaim) / 200
.mem(setaim) = 32000
End If
.aim = .aim + (.mem(aimsx) - .mem(aimdx)) / 200
If .aim > 2 * pi Then .aim = .aim - 2 * pi
If .aim < 0 Then .aim = 2 * pi + .aim
.aimx = Cos(.aim)
.aimy = Sin(.aim)
You can find it in Updvars2 in the robots module.The error occurs on line
Code: [Select]
.aim = .aim + (.mem(aimsx) - .mem(aimdx)) / 200
Holding the mouse over ".mem(aimsx)" gives -32000
Holding the mouse over ".mem(aimdx)" gives 1256
This is obviously going to push .aim beyond the 32768 limit and give us an overflow.
I thought I had fixed this ages ago by limiting .aim to a magnitude of 1256. The code to do it is right up there in this chunk of code.
See if you can spot the stupid ass mistake in it.