Author Topic: Strange Access Violation  (Read 805 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Strange Access Violation
« on: October 18, 2009, 11:35:34 pm »
Im doing some bug sweeping on my ZRPG script and came across the source of most if not all the access violations i still get, and i dont get what could be causing it...


GivePower is called in OnPlayerRespawn and perioticly in apponidle (only for a few zombies).
Here is the code:
Code: [Select]
procedure GivePower(ID: byte);
var power,hp,line: byte;
begin
try
line := 0;
power := sbot[ID].bonus; line := 1;
if power = 1 then hp := getplayerstat(ID,'health'); line := 2;
if power <> 255 then begin
givebonus(ID,power); line := 3;
if power = 1 then dodamage(ID,150-hp); line := 4;
end;
except
writeln('+++++++++++++++++++++++++++++++++++++++');
writeln('GivePower Error Captured');
writeln('Error: ' + exceptiontostring(exceptiontype,exceptionparam));
writeln('ID='+tostr(ID)+'('+getplayerstat(ID,'name')+')');
writeln('line='+tostr(line));
writeln('++++++++++++++++++++++++++++++++++++++++');
end;
end;

Most of the time it works with no problems. And it only seems to go off if the power is 1 (pred). Although i have not tested it with any others because zombies that get any other power perioticly would be invincible or it would be pointless.

(tostr() just takes in anything and outputs it in string form)

Here is the output of the exception (notice the line being null)
Code: [Select]
(23:32:44) +++++++++++++++++++++++++++++++++++++++
(23:32:44) GivePower Error Captured
(23:32:44) Error: Exception: Access violation at address 081153B6, accessing address 08B32CCA
(23:32:44) ID=(Vortex)
(23:32:44) line=
(23:32:45) ++++++++++++++++++++++++++++++++++++++++

Does anyone know what the deal is?

Thank You.



Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Strange Access Violation
« Reply #1 on: October 18, 2009, 11:44:27 pm »
Are you sure tostr works? The only two places I see it used it isn't printing anything (not just line, but also ID one line above that). Post it here and I can test it out. OR just use inttostr like a normal person.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Strange Access Violation
« Reply #2 on: October 18, 2009, 11:47:53 pm »
I use tostr in MANY places in the script, i know it works. I even use that same debug method in other places and the line thing works.


Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Strange Access Violation
« Reply #3 on: October 19, 2009, 12:00:26 am »
for the sake of debugging change it to inttostr and make sure that isn't a problem.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Strange Access Violation
« Reply #4 on: October 19, 2009, 12:08:27 am »
Ok, that is very strange, for some reason tostr isnt working here, but anyway... Here is the real output (the ID is not always 7)

Code: [Select]
(00:06:36) +++++++++++++++++++++++++++++++++++++++
(00:06:36) GivePower Error Captured
(00:06:36) Error: Exception: Access violation at address 081153B6, accessing address 08B32CCA
(00:06:36) ID=7(Vortex)
(00:06:36) line=2
(00:06:36) ++++++++++++++++++++++++++++++++++++++++

It seems like its reading the variable incorrectly from the sbot[ID].power


Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Strange Access Violation
« Reply #5 on: October 19, 2009, 12:15:38 am »
The error seems to be coming from one of these two lines:
Code: [Select]
if power <> 255 then begin
         givebonus(ID,power);
Are you sure you have this correct: power := sbot[ID].bonus;
Should it be sbot[ID].power?

If not then try echoing out ID and power to make sure that they aren't anything craaaazy.

EDIT: NVM all of that, the problem is that your ID is wrong. Whatever is calling it is causing the error. If you want to be lazy then encompass the whole thing in a getplayerstat(ID, 'active') or if you want to be good then figure out why it's being called with a bad ID.
« Last Edit: October 19, 2009, 12:21:33 am by iDante »

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Strange Access Violation
« Reply #6 on: October 19, 2009, 12:24:47 am »
Ok, its done but since theres no high levels ingame, which means no enemies with pred bonuses. I can spawn only 2 extra zombies because of Ec's cap. Ill edit this when the error happens again.


EDIT:
Code: [Select]
(00:43:57) +++++++++++++++++++++++++++++++++++++++
(00:43:57) GivePower Error Captured
(00:43:57) Error: Exception: Access violation at address 081153B6, accessing address 08B32CCA
(00:43:57) ID=17(Vortex) power=1
(00:43:57) line=2
(00:43:57) ++++++++++++++++++++++++++++++++++++++++
« Last Edit: October 19, 2009, 12:44:51 am by Hacktank »


Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Strange Access Violation
« Reply #7 on: October 19, 2009, 03:53:43 am »
One last thing to try:
getplayerstat(byte, 'health') returns an integer. dodamage takes an integer as the damage to do. Try changing hp to an integer. I'm not sure if that would cause access violations, but you never know ;)

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Strange Access Violation
« Reply #8 on: October 19, 2009, 06:10:38 pm »
Nope :\

Code: [Select]
(18:10:18) +++++++++++++++++++++++++++++++++++++++
(18:10:18) GivePower Error Captured
(18:10:18) Error: Exception: Access violation at address 081153B6, accessing address 08B32CCA
(18:10:18) ID=6(Vortex) power=1
(18:10:18) line=2
(18:10:18) ++++++++++++++++++++++++++++++++++++++++

From: October 20, 2009, 04:19:41 pm
From what i can gather it is an error in GiveBonus itsself. Because i get access violations sometimes when my players use the skill vanish (pred skill) whitch does a straight call of givebonus(ID,1) and does no damage or anything.
« Last Edit: October 20, 2009, 04:19:41 pm by Hacktank »