SRL Archive - Help and Support

Weird exception in my script.


EvilChicken!

2010-08-02 00:09:59

I've come across this error in my script which I simply cannot find a logical explanation for.

Error: Exception: The bitmap[2] does not exist at line 567

^This single line has been puzzling my mind for a couple of hours now.
Just so you know what I'm talking about, it happens in this:
if (FindBitmapToleranceIn(BarBmp, X, Y, MBX1, MBY1, MBX2, MBY2, 10)) then
:line, with these:
Debug_Ln('Bank_WithdrawBars: searching for SRL_BMP #' +
IntToStr(Queue[CP].Bar.bmpID) + ' - ' + Queue[CP].Bar.Name + ' bar.', DEBUG_MINOR);
BarBmp := srl_GetBitmap(Queue[CP].Bar.bmpID);
if (FindBitmapToleranceIn(BarBmp, X, Y, MBX1, MBY1, MBX2, MBY2, 10)) then
begin
Debug_Ln('Bank_WithdrawBars: Found ' + Queue[CP].Bar.Name +
' bar bitmap at ' + IntToStr(X) + ', ' + IntToStr(X) + '.', DEBUG_MINOR);
MMouse(X - Random(3), Y - Random(3), 3, 3);
: being the surrounding lines. For further examination, see the entire script attached below.

Now, I could most likely make some sort of workaround for this, but I just read this thread, and his error seems very similar to mine IMO – except that mine occurs during runtime and his during compiling.

I'm sorry to be asking, and I know that it's very possible that the error is somehow induced as a result of my own work – but I am simply curious as to what the solution might be.

I've attached the entire script below, including a test account which I just ran through Tutorial Island. Just open up RS and hit run, the error should occur a couple of seconds after opening the bank.

What puzzles me the most about this error, is that the lines 1002-1034 use the very same methods, and they seem to work pretty flawlessly.

Final notes: Yes, I am using the latest opendev with latest Simba (console says 707, afaik should be latest?)
If you come across any other mistakes I've made or things that should be improved, do let me know. Any comment is appreciated!


EDIT: My avatar is finally in it's correct element.

Cigue

2010-08-02 15:47:06

My experience with BMPs hasn't been very good.
Why don't you try this :
Writeln(IntToStr(BarBMP);
just after the BMP is loaded? Therefore you'd know if it was loaded or if the error commes from the part where you're loading it.

EvilChicken!

2010-08-02 17:51:36

Ahah, I figured it out.

srl_Getbitmap stores the retrieved bitmaps into a global array upon first request, so that when the bitmap is requested a second time, it simply retrieves it from the global array rather than the actual string listed in Bitmaps.scar.

Now, the thing I didn't think about, was that freeing the bitmap (what I thought only would be locally) also meant freeing it from the global array – I assumed that if one assigned an external array element to a local variable, the variable would act as an independent copy of the original, being totally unrelated to its origin.

program new;
{$i SRL/SRL.scar}

var
tmpBMP, I, X, Y: Integer;

begin
SetUpSRL;

for I := 0 to 1 do
begin
tmpBMP := srl_GetBitmap(bmp_Bar_Bronze);

if (FindBitmapToleranceIn(tmpBMP, X, Y, MBX1, MBY1, MBX2, MBY2, 10)) then
WriteLn('Player has bronze bars.')
else
WriteLn('No bars found.');
// FreeBitmap(tmpBMP); <--
end;
end.

The error I was getting, can be simulated by un-commenting the marked line.

Also, thanks for the suggestion, Cigue. :)

Wizzup?

2010-08-03 03:37:19

Suddenly doesn't make the exception too weird after all. ;)