Jump to content
Bixby Sayz

Fun with try...finally

Recommended Posts

Anyone want to explain to me why...

 

This generates a runtime error:

 

[sCAR]program New;

 

{$DEFINE RS2}

{$I OSI\OSI.scar}

 

begin

SetUpOSI();

try

Exit;

finally

CloseBank(True);

end;

FreeOSI();

end.

[/sCAR]

 

But this works fine:

 

[sCAR]program New;

 

{$DEFINE RS2}

{$I OSI\OSI.scar}

 

begin

SetUpOSI();

try

;

finally

CloseBank(True);

end;

FreeOSI();

end.

[/sCAR]

 

Note: Must be logged into RuneScape and bank (any bank) must be open for this to exhibit. Doesn't happen if bank is closed.

 

I give up trying to figure it out. At least I have the satisfaction of knowing what is causing bizarre runtime errors every time I sit down to rewrite my scripts so I can work around it. The error only exhibits if Exit is called inside the try...finally.

 

Everytime I start rewriting my scripts to make them work I get bizarre errors like this and spend weeks running in circles trying to figure out what the heck is going on. Eventually I give up in frustration and the scripts never get written.

Link to comment
Share on other sites

It's an obscure bug/issue that has driven me round the bend for ages.

 

In this scaled down example I listed above: If the Exit statement is executed inside a try/finally and if (and only if) the bank screen is open I get a runtime error at line 1 (invalid opcode). If the bank is closed it runs fine.

 

In my script I have a CloseBank(True) in the finally portion. If the Exit statement is called inside the try/finally and if (and only if) the bank screen is open it generates a runtime error (invalid range) in LoadTextTPA at the very first statement. (CloseBank calls BankScreen which calls FindTextTPAInTPA which calls LoadTextTPA). In trying to track this down I wrapped the entire contents of LoadTextTPA in a try/except. The error then occurs at the end of the proc outside the try/except.

 

At this point I give up and decide to go do something more fun like slam my fingers repeatedly in a drawer.

Link to comment
Share on other sites

Lol, some of the text tpa functions, I've had problems with them before too, with errors sometimes. Someone else too I think has posted about this in the past. It probably has to do with an access error? Invalid range, so invalid pixel, or something...

 

Try putting the text tpa functions in your script, and ripping them from OSI. Then Dissect the text tpa functions, with and without OSI maybe.

 

GL

Link to comment
Share on other sites

I have started using try..except..finally..end;, because it seems like adding that except part there does fix some of the problems. :)

Not sure if it will work with your problem, but at least give it a try?

 

program New;

{$DEFINE RS2}
{$I OSI\OSI.scar}

begin
 SetUpOSI();
 try
   Exit;
 except
   WriteLn('There was an error..?');
 finally
   CloseBank(True);
 end;
 FreeOSI();
end.

 

-Jani

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...