SRL Archive - OSR Help

Not freeing DTM's


Twinki

2013-07-03 16:41:15

I've made a kinda ghetto DTM counter for an RSPS, but the problem is I keep getting a bunch of 'The following DTM's were not freed' messages in the debug.

The following DTMs were not freed: [2, 3, 4, 5, 6, 7, 8, 9]

Sometimes it'll be a lot more.

procedure CountLividPlants;
var
thisTPA:TPointArray;
LividPlant, P:Integer;
begin
LividPlant := DTMFromString('mggAAAHicY2NgYChlYmBIhOJsIK4G4jIgfgmUuwnED4H4IxC/B+I7QFwZ7gIkmTAwKwN2wIgDQwAAeEIJLg==');
wait(500);
FindDTMs(LividPlant, thisTPA, RL_MIX1, RL_MIY1, RL_MIX2, RL_MIY2);
P := Length(thisTPA);
Plants := P / 9
writeln(IntToStr(Plants));
end;

Basically all it does is count how many LividPlant DTM's are in my inventory and returns the count. (Had to add the divide by 9 because for some reason the numbers kept returning as 9 * the actual Inventory count) Also I couldn't use any of the functions like CountItemsIn because they wouldn't work with the RSPS.

Anyways, I did add FreeDTM(LividPlant); to the main loop and it still didn't fix the problem.

rj

2013-07-03 16:46:03

make a procedure to free them

Procedure freememory;
begin
freedtm(lividPlant);
end;

the in the main loop add "addonterminate('freeMemory');

That way, when the script ends it does that procedure which is to free the dtm

Twinki

2013-07-03 16:49:35

From: Officer Barbrady
make a procedure to free them

Procedure freememory;
begin
freedtm(lividPlant);
end;

the in the main loop add "addonterminate('freeMemory');

That way, when the script ends it does that procedure which is to free the dtm


Still get the same error :( and a new one :blink:

Exception in Script: The given DTM Index[0] doesn't exist
The following DTMs were not freed: [2, 3, 4, 5, 6, 7, 8, 9]

Kevin

2013-07-03 16:53:33

Since you make the DTM every single time you enter the method, you'll need to Free it at the end of that call:
procedure CountLividPlants;
var
thisTPA:TPointArray;
LividPlant, P:Integer;
begin
LividPlant := DTMFromString('mggAAAHicY2NgYChlYmBIhOJsIK4G4jIgfgmUuwnED4H4IxC/B+I7QFwZ7gIkmTAwKwN2wIgDQwAAeEIJLg==');
wait(500);
FindDTMs(LividPlant, thisTPA, RL_MIX1, RL_MIY1, RL_MIX2, RL_MIY2);
FreeDTM(LividPlant);
P := Length(thisTPA);
Plants := P / 9
writeln(IntToStr(Plants));
end;

Also it's 9 times larger than you expect because you have an area tolerance in your DTM. For some reason by default the DTM Editor adds an area tolerance of 1 to every point. That means a point can match exactly, or in any of the pixels in the 3x3 box around it (3x3 making 9). Because of all those extra options, each item is being matched 9 times. Change your area tolerance to 0 and it should be fine :)

Twinki

2013-07-03 16:59:02

From: Kevin
Since you make the DTM every single time you enter the method, you'll need to Free it at the end of that call:
procedure CountLividPlants;
var
thisTPA:TPointArray;
LividPlant, P:Integer;
begin
LividPlant := DTMFromString('mggAAAHicY2NgYChlYmBIhOJsIK4G4jIgfgmUuwnED4H4IxC/B+I7QFwZ7gIkmTAwKwN2wIgDQwAAeEIJLg==');
wait(500);
FindDTMs(LividPlant, thisTPA, RL_MIX1, RL_MIY1, RL_MIX2, RL_MIY2);
FreeDTM(LividPlant);
P := Length(thisTPA);
Plants := P / 9
writeln(IntToStr(Plants));
end;

Also it's 9 times larger than you expect because you have an area tolerance in your DTM. For some reason by default the DTM Editor adds an area tolerance of 1 to every point. That means a point can match exactly, or in any of the pixels in the 3x3 box around it (3x3 making 9). Because of all those extra options, each item is being matched 9 times. Change your area tolerance to 0 and it should be fine :)


Ahhhhh was trying to figure why it was 9 times larger for like 2 hours…

And that did help, but I still get the error but it's always this now:

The following DTMs were not freed: [2]

Kevin

2013-07-03 17:03:31

From: Twinki
Ahhhhh was trying to figure why it was 9 times larger for like 2 hours…

And that did help, but I still get the error but it's always this now:

The following DTMs were not freed: [2]


Then there's likely a DTM elsewhere you're not freeing?

Twinki

2013-07-03 17:10:18

From: Kevin
Then there's likely a DTM elsewhere you're not freeing?


Fixed it, had to add another FreeDTM(LividPlant); to the main loop at the beginning and end.

Thanks guys :)