SRL Archive - Jr. Member General Help and Discussion

OpenGL GLX Access violation


Mark

2013-09-13 09:01:01

Hi guys been Playing with Brandons GLX again this time with getting the nearest model using the following code


program new;
{$X+}
{$DEFINE SMART}
{$I GLX/Setup.Simba}

Function glGetNearestModelPos(ModelID:Cardinal):TPoint;
var
T: glModelArray; I,BestPick:Integer; DistArr:TIntegerArray; Points:TPointArray;
begin
T:= glGetModels(ModelID);
SetLength(T, High(T));
if Length(T) > 0 then
begin
SetLength(Points, High(T));
SetLength(DistArr, High(T));
for I := 0 to High(T) do Points[I]:=Point(T[I].X, T[I].Y);
for I := 0 to High(T) do DistArr[I]:=Distance(Points[I].x,Points[I].y,678,343);
for I := 0 to High(T) do if (DistArr[I] < DistArr[BestPick]) then BestPick := I;
Result:=Points[BestPick];
end else writeln('Cant Find Model:' + ToStr(ModelID) + ' On Screen Please Check ID is Correct');
end;

var
Smart: TSmart;
TP:TPoint;
begin
SetupGLX(Smart, 1360, 670);
//glDebug(2, 0, 0, 0, Smart.Height, Smart.Width);

TP:=glGetNearestModelPos(3910352186);
Mouse(TP.x, TP.y, 1, 1, Mouse_Right);
end.

Code Seems to work well it finds the nearest model successfully moves mouse then right clicks as it should but then simba crashes and i get this error in the debug any info to why this is happening would be very much appreciated.

Here is the error message in the from the console.

thanks in advance guys…

riwu

2013-09-13 09:12:59

SetLength(T, High(T));
Why do u reduce the length of T by 1?

I've this in a script i'm making for sorting tpoints too.

var highTm:= High(tm);
var TPA: TPointArray;
SetLength(TPA, highTm + 1);
var i: Integer;
for i:=0 to highTm do
TPA[i]:= Point(tm[i].X, tm[i].Y);

SortTPAFrom(TPA, PlayerCentre);

Try adding a TerminateScript at the end (read some where about having to do that for lape atm), and add some writeln to see where exactly simba crashed? like

Mouse(TP.x, TP.y, 1, 1, Mouse_Right);
writeln(1);
TerminateScript;
end.

Mark

2013-09-13 09:29:10

From: riwu
SetLength(T, High(T));
Why do u reduce the length of T by 1?

I've this in a script i'm making for sorting tpoints too.

var highTm:= High(tm);
var TPA: TPointArray;
SetLength(TPA, highTm + 1);
var i: Integer;
for i:=0 to highTm do
TPA[i]:= Point(tm[i].X, tm[i].Y);

SortTPAFrom(TPA, PlayerCentre);

Try adding a TerminateScript at the end (read some where about having to do that for lape atm), and add some writeln to see where exactly simba crashed? like

Mouse(TP.x, TP.y, 1, 1, Mouse_Right);
writeln(1);
TerminateScript;
end.


Hehe cheers bud overlooked the SetLength all fixed now Rep'd

Brandon

2013-09-13 10:13:50


function ModelsToTPA(var Models: glModelArray): TPointArray;
var
I: Integer;
TPA: TPointArray;
Begin
SetLength(Result, Length(Models));
For I := 0 To High(Models) Do
Begin
Result[I] := Point(Models[I].X, Models[I].Y);
End;
End;

Then just do:


SortTPAFrom(ModelsToTPA(Models), Point(X, Y));
Mouse(TPA[0], MOUSE_RIGHT);