I broke AGS...

Started by suicidal pencil, Sun 15/11/2009 06:07:54

Previous topic - Next topic

suicidal pencil

---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x00506B3B ; program pointer is +5, ACI version 3.12.1074, gtags (0,50)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and post the details on the AGS Technical Forum.



Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.

An error file CrashInfo.dmp has been created. You may be asked to upload this file when reporting this problem on the AGS Forums. (code 0)
---------------------------
OK  
---------------------------

Here's what happened: I have a function that accelerates the player downwards, and is eventually stopped when they hit the ground.

Code: ags

function Downward_acceleration(int Acceleration, int StartingVelocity)
{
  //a = (v2-v1)\t 
  //Acceleration equals Final Velocity minus Initial Velocity over Time
  //v2 = at+v1
  //Final Velocity equals Acceleration multiplied by Time plus initial velocity
  int FinalVelocity = (Acceleration*1)+StartingVelocity;
  return FinalVelocity;
}
.
.
.
function repeatedly_execute() 
{
  if(Ground_collision == false)
  {
    player.y += Downward_acceleration(YA, YV1);
    YV1 += Downward_acceleration(YA, YV1);
    if(YA <= 3) YA++;
  }
}


Only, when I tested it, I had accidentally put '-=' instead of '+=' in the line 'player.y += Downward_acceleration(YA, YV1);'. So instead of traveling downwards, where the player would have stopped, the player launched into the sky, and eventually produced the error above

thoughts?

Wonkyth

Well, an integer can only be so big, and if the player was accelerating then it wouldn't take long to reach the limit.
"But with a ninja on your face, you live longer!"

suicidal pencil

#2
Quote from: wonkyth on Sun 15/11/2009 06:46:54
Well, an integer can only be so big, and if the player was accelerating then it wouldn't take long to reach the limit.

yes, but the acceleration was limited. I did a data test using my native language (Perl), using the same values as in my script, and got the following results (because the ending number was the amount of pixels to move, I totaled it as well):
Code: ags

code:

#!/usr/bin/perl -w
use strict;

my $acc = 0;
my $stv = 0;
my @total;
open FILE, ">>", "data.txt" || die $!;
for(my $counter = 1; $counter <= 26; $counter++)
{
	my $fv = ($acc*1)+$stv;
	push(@total, $fv);
	my $total_pixels = 0;
	foreach my $element(@total)
	{
		$total_pixels += $element;
	}
	print FILE "Loop $counter: $fv Total: $total_pixels pixels\n";
	$stv = $fv;
	$acc >= 3 ? print "" : $acc++;
}
close(FILE);


output:

Loop 1: 0 Total: 0 pixels
Loop 2: 1 Total: 1 pixels
Loop 3: 3 Total: 4 pixels
Loop 4: 6 Total: 10 pixels
Loop 5: 9 Total: 19 pixels
Loop 6: 12 Total: 31 pixels
Loop 7: 15 Total: 46 pixels
Loop 8: 18 Total: 64 pixels
Loop 9: 21 Total: 85 pixels
Loop 10: 24 Total: 109 pixels
Loop 11: 27 Total: 136 pixels
Loop 12: 30 Total: 166 pixels
Loop 13: 33 Total: 199 pixels
Loop 14: 36 Total: 235 pixels
Loop 15: 39 Total: 274 pixels
Loop 16: 42 Total: 316 pixels
Loop 17: 45 Total: 361 pixels
Loop 18: 48 Total: 409 pixels
Loop 19: 51 Total: 460 pixels
Loop 20: 54 Total: 514 pixels
Loop 21: 57 Total: 571 pixels
Loop 22: 60 Total: 631 pixels
Loop 23: 63 Total: 694 pixels
Loop 24: 66 Total: 760 pixels
Loop 25: 69 Total: 829 pixels
Loop 26: 72 Total: 901 pixels


Resolution is 640 x 400, and the integer goes over 640 at loop 23, but I've used locations outside resolution before without a problem.  

edit: Figured it out. The limit on player.y is 32767 (being a signed int), and that happy little script of mine exceeds that limit at loop 150:

Code: ags

Loop 1: 0 Total: 0 pixels
Loop 2: 1 Total: 1 pixels
Loop 3: 3 Total: 4 pixels
Loop 4: 6 Total: 10 pixels
Loop 5: 9 Total: 19 pixels
.
.
.
Loop 145: 429 Total: 30889 pixels
Loop 146: 432 Total: 31321 pixels
Loop 147: 435 Total: 31756 pixels
Loop 148: 438 Total: 32194 pixels
Loop 149: 441 Total: 32635 pixels
Loop 150: 444 Total: 33079 pixels


At a speed of 40 loops per second, then it would take 3.75 seconds to hit that limit. :-\ It's worse if acceleration was unbounded: it would take 59 loops, or 1.475 seconds to hit the limit  :-[

Pumaman

Hmm, that still shouldn't crash the engine though. I'll see if I can reproduce it.

SMF spam blocked by CleanTalk