Code center > Solved Bugs
runtime 6/compile error
PurpleYouko:
I just remembered what happened.
.MaxVel never existed.
maxvel was added as a sysvar and is based on a local variable called "Maxspeed" that is calculated in subroutine "updpos" in the Physics module.
The formula for Maxspeed is
--- Code: ---Maxspeed = 30 / (.mass / 2)
--- End code ---
Since robots are supposed to have a minimum mass of 1, this results in a ceiling value of 60
I have extensively tested the actual speed limit code (also found in the same subroutine) by manually entering all kinds of weird and huge numbers into .vx and/or .vy and can safely say there is nothing wrong with this part of the code.
--- Code: ---vt = Sqr(.vx ^ 2 + .vy ^ 2)
If vt > Maxspeed Then 'top speed limit routine 2 changed faster speeds for lower mass robots
Reduce = vt / Maxspeed
.vx = .vx / Reduce
.vy = .vy / Reduce
End If
--- End code ---
So the only thing left is that somehow the mass of the robot is getting too small so that Maxspeed is coming back huge.
So I'm off to test that now.
PurpleYouko:
Next update.
Robot mass is defined in routine "updvars2" in the "Robots" module
--- Code: ---.mass = 1 + (.body / 10000) + (.Shell / 200) 'set value for mass
Maxspeed = 30 / (.mass / 2) 'Set maximum speed. Absolute max = 60
--- End code ---
You will note that the same Maxspeed calculation is in here too. This one is applied to limit acceleration vectors prior to passing the program flow to the afore mentioned "updpos" routine
As you will see from this formula, the only way to make Maxspeed bigger than 60 is to have a mass of less than 1.
this can be achieved in two ways
One way is to have a body size that is large and negative, A body of -10000 would yield infinite Maxvel and would crash the program right here.
Another is for shell to be negative and close to 200 in size.
I have manually put all kinds of values in here and none cause the crashes reported since even a maxspeed value of 32000 doesn't crash anywhere
Since the reported crashes only occur when one robot sees another with a huge velocity, this isn't really surprising. It could go un-noticed for a few cycles before it becomes an issue.
However, a negative body could not go un-noticed as the bot will die on the following cycle.
Negative shell? Now that is a different matter. It won't have any direct effect on the bots life other than dramatically reducing its mass.
The plot thickens and the delving into the code continues. More in a bit.
PurpleYouko:
Unable to find any way to make .shell or .body negative. Every test was caught by the automatic limits already in place in the software and set back to a valid value.
The only remote possibility is if the offending robot is a corpse which would allow it to have a negative body (maybe)
I have modified the code in "updvars2" in the robots module as follows
Before
--- Code: ---With rob(n)
.mass = 1 + (.body / 10000) + (.Shell / 200) 'set value for mass
Maxspeed = 30 / (.mass / 2) 'Set maximum speed. Absolute max = 60
Absaccel = 0 'reset acceleration
If Abs(.vx) > 32000 Then .vx = 32000 * Sgn(.vx)
If Abs(.vy) > 32000 Then .vy = 32000 * Sgn(.vy)
.absvel = Cos(.aim) * .vx * -1 + Sin(.aim) * .vy 'formula changed to give velocity in the direction robot is facing rather than always a positive number. Make *.vel work properly.
--- End code ---
after
--- Code: ---With rob(n)
If .Shell < 0 Then .Shell = 0
If .body < 0 Then .body = 0: .Dead = True
.mass = 1 + (.body / 10000) + (.Shell / 200) 'set value for mass
Maxspeed = 30 / (.mass / 2) 'Set maximum speed. Absolute max = 60
Absaccel = 0 'reset acceleration
If Abs(.vx) > 32000 Then .vx = 32000 * Sgn(.vx)
If Abs(.vy) > 32000 Then .vy = 32000 * Sgn(.vy)
.absvel = Cos(.aim) * .vx * -1 + Sin(.aim) * .vy 'formula changed to give velocity in the direction robot is facing rather than always a positive number. Make *.vel work properly.
--- End code ---
This should prevent any possible huge value of Maxspeed ever occuring.
Without huge Maxspeed, you can't have huge speed so the refvel stuff where the error was actually spotted, should be fixed.
I won't move this to the fixed thread yet until the repair is confirmed.
PurpleYouko:
Could someone please confirm that Corpses were enabled in sims that produced this fault?
Testlund:
I allways have corpses turned on so it could very well be. But I'm getting a little confused here now. You're talking about more than one solution here for the same overflow error, is that right? I've lost track what to change first. see my post 'Still get overflows' where you mension another solution.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version