SRL Archive - Bugs

[RESOLVED] Access Violation with new SPS (again) ~ Need suggestions


Coh3n

2012-03-28 15:10:08

FIXED: http://villavu.com/forum/showpost.php?p=978487&postcount=12

Link to SPS source: https://github.com/Coh3n/SPS/blob/sps_2.0/plugin/source/sps.lpr

Back again with an access violation with the new (unreleased) SPS. I'm looking for suggestions on things to try to pinpoint the error, or better yet, resolve it.

Error:

Error: Exception: Access violation at line 254
Line 254:

SmallMap := SPS_BitmapToMap(Minimap, SPS_SIDE_LENGTH);
SPS_BitmapToMap, from the plugin:

function SPS_BitmapToMap(bmp: TMufasaBitmap; SideLength: integer): T3DIntegerArray; register;
var
X, Y, HighX, HighY: integer;
begin
HighX := Trunc(bmp.Width / (SideLength * 1.0));
HighY := Trunc(bmp.Height / (SideLength * 1.0));

SetLength(Result, HighX);
for X := 0 to HighX - 1 do
begin
SetLength(Result[X], HighY);
for Y := 0 to HighY - 1 do
begin
Result[X][Y] := SPS_MakeColorBox(bmp, X * SideLength, Y * SideLength, SideLength);
end;
end;
end;
What I've figured out:
  • The plugin memory manager is exported exactly as it is in the old SPS. You can check the source here.
  • It only happens when SPS_GetMyPos() has been called more than once.
  • It only happens when Simba is opened by double clicking the .simba file. If it's opened any other way, there's no error. This is what I find really strange.
  • The bitmap (Minimap) is valid. If it wasn't, Simba would give another error when SPS_GatherMinimap is called. It's also debugged in SPS_GetMyPos(), and everything is normal.
  • I've run Simba through Lazarus, and all I got was this and this.
  • When the test script is opened, there's no indication in the cmd of the plugin memory manager being set (not sure if there's supposed to be).
If you want to test, download SPS to Simba/Includes, replace your plugin with the new one, and run this script (have your player in VWB if you don't know how to set it up):

program spsTest;
//{$DEFINE SMART}
{$i srl/srl.simba}
{$i sps/sps.simba}

procedure antiban();
begin
end;

begin
smart_server := 1;
smart_members := false;
smart_signed := true;
smart_superDetail := false;

activateClient();
clearDebug();
setupSRL();

SPS_Debug := true;
SRL_Procs[SRL_Antiban] := @antiban;

//Writeln(toStr(SPS_WindWalk(point(4353, 3025))));
//Writeln(toStr(SPS_WindWalk(point(4579, 2906))));

//SPS_Setup(RUNESCAPE_SURFACE, ['11_7', '12_7']); // VEB
//SPS_Setup(RUNESCAPE_SURFACE, ['11_7']); // Varrock Center
//SPS_Setup(RUNESCAPE_SURFACE, ['12_9']); // AK Bank
//SPS_Setup(RUNESCAPE_SURFACE, ['10_8', '10_9']); // DB

SPS_Setup(RUNESCAPE_SURFACE, ['10_7', '11_7']); // VWB
SPS_GetMyPos();
SPS_GetMyPos(); // error occurs on this call, not the first
SPS_GetMyPos();
end.
Any suggestions are appreciated.

Thanks in advance,
Cohen

Markus

2012-03-28 15:15:24

Comment out the make colour box, add a writeln right after begin and tell me if it actually does write in console.
About mem manager setting: you can add that with a writeln yourself to plugin.

Coh3n

2012-03-28 15:27:20

From: Markus
Comment out the make colour box, add a writeln right after begin and tell me if it actually does write in console.
Will do as soon as I can. E: Yes, it writes in the console.

From: Markus

About mem manager setting: you can add that with a writeln yourself to plugin.
Ah, right, of course. :duh: E: Nothing gets written. Does the SetPluginMemoryManager have to be included in the GetFunctionInfo method? Or is it enough that it says "exports SetPluginMemoryManager;" at the end of the file?

Markus

2012-03-29 03:56:30

Exports itself should do, Simba checks if it's exported.
Also, if it writes in console then at least some part of the function calling works.

Edit: You ARE using Same FPC, Lazarus and MML version that is used for compiling Simba, right?

Coh3n

2012-03-29 13:28:19

From: Markus
Exports itself should do, Simba checks if it's exported.
Also, if it writes in console then at least some part of the function calling works.

Edit: You ARE using Same FPC, Lazarus and MML version that is used for compiling Simba, right?
Does it matter? I can compile Simba myself if that helps. I know I'm using the same FPC version for sure, not sure about Laz or MML, though.

Markus

2012-03-29 15:33:15

Idk if the structure of bitmaps changed, but just to be sure :) Compile Simba and SPS against same version/source.

Coh3n

2012-03-30 00:50:04

From: Markus
Idk if the structure of bitmaps changed, but just to be sure :) Compile Simba and SPS against same version/source.
Didn't change anything. :(

Wizzup?

2012-03-30 20:39:52

From: Coh3n
Ah, right, of course. :duh: E: Nothing gets written. Does the SetPluginMemoryManager have to be included in the GetFunctionInfo method? Or is it enough that it says "exports SetPluginMemoryManager;" at the end of the file?


This should be a priority. I'm 99% sure that it is failing due to memory management issues. If the SetPluginMemoryManager function is not called, something is wrong. I can look at this in a bit.

Coh3n

2012-03-31 14:16:15

From: Wizzup?
This should be a priority. I'm 99% sure that it is failing due to memory management issues. If the SetPluginMemoryManager function is not called, something is wrong. I can look at this in a bit.
Okay. I can try a couple more thing when I get home tomorrow. I'll try exporting it the same way the other functions are, and I can try calling it in the script. If that works, we know Simba isn't calling it.

E: I was going to try to call SetPluginMemoryManager in the script, but quickly realized that there's no TMemoryManager type to associate with the parameter, but I did add a writeln() to the method and nothing was written in the console when the script was loaded (no matter now I loaded it).

pencilbi

2012-04-02 06:13:43

i met this problem:
Error: Exception: Access violation at line 254

SmallMap := SPS_BitmapToMap(Minimap, SPS_SIDE_LENGTH);

Markus

2012-04-02 08:44:28

Pointer(SetPluginMemManager) := GetProcAddress(Plugin, PChar('SetPluginMemManager'));

Typo, you got SetPluginMemoryManager, but that won't work ;) It needs to be SetPluginMemManager. Also, Simba will do the writeln.

Coh3n

2012-04-02 12:18:25

From: pencilbi
i met this problem:
Error: Exception: Access violation at line 254

SmallMap := SPS_BitmapToMap(Minimap, SPS_SIDE_LENGTH);
Yes, thanks, that's exactly what this thread is for.

From: Markus
Pointer(SetPluginMemManager) := GetProcAddress(Plugin, PChar('SetPluginMemManager'));

Typo, you got SetPluginMemoryManager, but that won't work ;) It needs to be SetPluginMemManager. Also, Simba will do the writeln.
Bah! How silly. Shouldn't there be a warning about that or something? Like warn the user if a plugin doesn't have SetPluginMemManager?

I don't have time to check now, but that's probably the issue. I'll test it later today.

iBlank

2012-04-02 12:26:32

I have no idea what is causing the error and won't pretend so, but like you have already posted:

I got the error.
Closed Simba.
Opened Simba by right clicking>run as administrator.
Ran script with no errors.

Hope this is helpful somehow!

Coh3n

2012-04-02 14:11:48

Fixed in the latest version! Thanks Markus. :)

Kyle Undefined

2012-04-02 15:39:09

So does this mean that SPS 2.0 will be released after some testing?

Coh3n

2012-04-02 16:38:53

Yeah. I'd like to look into getting it to work no matter the compass angle, but I'm not sure if I'll have time for that. It shouldn't be that hard. It's just a matter of rotating the minimap bitmap created in SPS_GetMyPos.

There's also a small bug I think I found when combining the areas. I'll have to look into that later.

Olly

2012-04-02 17:46:12

Coh3n does the post have the updated sps files. (after the fix?)

Coh3n

2012-04-02 18:53:25

From: Ollybest
Coh3n does the post have the updated sps files. (after the fix?)
The post doesn't have any files. It just links to the repository (which should always be the most up to date version).