SRL Archive - Help

How do you debug objects?


rj

2015-03-21 12:45:35

How on earth do you debug objects? I'm confused as to why I have to put in a parameter for some object type

procedure debugObject(name:String);
var
bmp, i:integer;
objects: TReflectObjectArray;
obj2:TObjectType;
begin
Reflect.Graphics.Create(bmp);
objects.Get(obj2, name, 103); // what is the parameter tobjecttype there for?
for i := 0 to high(objects) do
Reflect.Graphics.DrawClippedText(toStr(objects[i].getName), 'smallchars07', Point(5, 0)); // ?? cant get tpoint

Reflect.Graphics.Free();
end;

Gives a access violation. But how else am i supposed to loop through a object array, the only properies of TReflectObjectArray was get

bg5

2015-03-21 12:58:46

TObjType = (objNull, objGame, objWallDecoration, objFloorDecoration, objBoundary);

https://villavu.com/forum/showthread.php?t=111664&p=1334326

Dunno where is an access violation, if array is empy for loop shoudn't start.

Turpinator

2015-03-21 13:00:37

From: rj


objects.Get(obj2, name, 103); // what is the parameter tobjecttype there for?


GroundObject, WallObject, NPCObject, etc. (those probably arent the actual names)

rj

2015-03-21 13:11:40

@bg5; @Turpinator;

procedure debugObject(name:String);
var
bmp, i:integer;
objects: TReflectObjectArray;
//obj2:TObjectType;
begin
Reflect.Graphics.Create(bmp);
objects.Get(objGame, name, 103);
writeln(objects);
if (length(objects) = 0) then
begin
writeln('Empty object array');
Reflect.Graphics.Free();
exit();
end;
for i := 0 to high(objects) do
Reflect.Graphics.DrawClippedText(toStr(objects[i].getName), 'smallchars07', Point(0, 5)); // ?? cant get tpoint

Reflect.Graphics.Free();
end;


I now have a access violation

Object Reference Leaked in: Get3DObject
Please report this log to the reflection team, terminating
[13:09:11:881] [Reflection] [Status] All cached references free'd from memory
Error: Access violation at line 39
Execution failed.
The following bitmaps were not freed: [1]

There is some sort of error going on with objects.get causing the bitmap not to free in the code below it.

Am I using it wrong or does it need to be reported as a bug?

Brandon

2015-03-21 13:38:03

I'm not sure whether you realise this or not, but your access violation is probably not for TReflectObjectArray.Get.

Your code is error prone..


Reflect.Graphics.Create(bmp);

attempts to create a TMufasaBitmap from a non-existent image (bmp is local and un-initialised).. If https://github.com/Elfyyy/OSR-Reflection/blob/3858b2043e342793c118bfa5c8bf8e334dc66bef/lib/internal/smart/Graphics.simba#L70

returns nil and you call Self.Bmp.GetWidth on the next few lines, you're access violating for accessing a null pointer. And that would because you're trying to access a non-existent bitmap. You need to make sure your resources exist before attempting to use them. Otherwise, you're looking for trouble and it's not always easy to track down (although this one is fairly obvious).


I don't think it's a bug in the include because I don't believe that the include should check your resources existence for you. Fix that and report back. If the problem still occurs, then it might be the include or you might be using it wrong.

rj

2015-03-21 13:56:29

From: Brandon
I'm not sure whether you realise this or not, but your access violation is probably not for TReflectObjectArray.Get.

Your code is error prone..


Reflect.Graphics.Create(bmp);

attempts to create a TMufasaBitmap from a non-existent image (bmp is local and un-initialised).. If https://github.com/Elfyyy/OSR-Reflection/blob/3858b2043e342793c118bfa5c8bf8e334dc66bef/lib/internal/smart/Graphics.simba#L70

returns nil and you call Self.Bmp.GetWidth on the next few lines, you're access violating for accessing a null pointer. And that would because you're trying to access a non-existent bitmap. You need to make sure your resources exist before attempting to use them. Otherwise, you're looking for trouble and it's not always easy to track down (although this one is fairly obvious).


I don't think it's a bug in the include because I don't believe that the include should check your resources existence for you. Fix that and report back. If the problem still occurs, then it might be the include or you might be using it wrong.


How do you even use the graphics then? This worked fine for me:

procedure debugTile();
var
p:TPoint;
bmp:integer;
begin
p := Reflect.Tiles.GetGlobalTile();
Reflect.Graphics.Create(bmp);
Reflect.Graphics.DrawClippedText(toStr(p), 'smallchars07', Point(5, 5), Tcolor(65280));
Reflect.Graphics.Free();
end;

Kyle

2015-03-21 14:24:50

Yes, Brandon is correct. In order to use the graphics within the include you need to change your draw function to the following:
Reflect.Smart.Graphics.DrawClippedText(toStr(objects[i].getName), 'smallchars07', Point(5, 0));

Also, remove: Reflect.Graphics.Create() and it should work..

I will be changing it so you don't have to do it this way soon, but i'm super busy with school lately and haven't had much time.