Darwinbots Forum
Code center => Bugs and fixes => Solved Bugs => Topic started by: PurpleYouko 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
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
.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.
-
mem(aimsx) = 1256 * Sgn(.mem(aimsx))
Does this do what I think it does?
If the absolute value of .aim is > 1256 then multiply it by the sign? Won't you always end up with the absolute value of what .aim was to begin with?
-
No you will end up with a value of 1256 multiplied by the original sign of the value.
Example
-2598 will become -1256
6589 will become 1256
All it does is to cap the value without changing the sign.
[hint]Look at the condition before this[/hint]
-
I don't think I touched the aiming controls in 2.37.4 (totally code raped them in 2.4 however ;))
DL 2.4 and find where I handle turning (I thinks its called SetAImFUnc or something like that, I'd have to look to be sure) and see how I did it, while we're cracking down on bugs ;)
-
I have already fixed this BTW. I just want to see if anybody else can see the glaringly obvious cock up before I tell them what it is.
I am pretty sure this is code that I added myself so I'm the one who did the dirty deed.
-
Omg! Might have just realised... it's the abs value of the condition, not the abs value of .aim used in the condition!
Please say I'm right, or I'll be well embarassed. :redface:
-
That's what I got |) (<-- LaForge from star trek smiely ;))
-
HEHEHE
Partly
You ARE right that it is the abs value of the condition that is used to determine the value of .aimsx and .aimdx.
That isn't the error though.
Look very carefully at the condition. cough "brackets" cough
-
I'm guessing you need
(Abs(.mem(aimsx)) > 1256)
instead?
-
here is a close up :D
[span style=\'font-size:14pt;line-height:100%\']If Abs(.mem(aimsx) > 1256) Then [/span]
-
Nope you lost me ;)
-
I'm guessing you need
(Abs(.mem(aimsx)) > 1256)
instead?
Nope. Sorry
-
Nope you lost me ;)
Oh come on. It's obvious. What is that condition going to do?
-
look at what is INSIDE the ABS() brackets.
-
...that shouldn't be.....
-
You tell me the ansewr and I'll let you know if I saw it or not :lol:
-
How can you take the absolute value of a boolean?!
-
:P
-
What do I have to do? Hold your hand?
-
The only blaring mistake I see is that it should be If Abs(.mem(aimsx)) > 1256 Then
-
Yes! I agree!
-
WOOHOOO :clap: :party:
You got it.
The way it was written, it didn't matter how big .aimsx got. The function always returned 0 as the condition. I.e. it NEVER fulfilled the condition and limited .aimsx to 1256.
-
Weren't we saying that way back at the beginning though? I thought there was something else I wasn't seeing.
-
So here is the crash fix for those of out there who give a crap.
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))
becomes
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))
-
I'm guessing you need
(Abs(.mem(aimsx)) > 1256)
instead?
is different from
If Abs(.mem(aimsx)) > 1256 Then
How?
-
An extra set of parenthesese :lol:
-
Ah they can make all the difference! :ph43r:
-
Sorry Ulc. I didn't notice you had moved a bracket. All I noticed was the extra one before the ABS.
The way you wrote it should work OK but the outer bracket set is just superfluous.
-
Ah, isn't coding wonderful ;)