PDA

View Full Version : [OGL] !AddGlobalType Error with TBoxArray



Swag Bag
07-20-2015, 05:35 PM
Hi I'm trying to create a TBoxArray and store Tboxes into it, but I'm running into an error whenever I try to put a TBox into an index of the array. Here is the code:
procedure tlobby.setupSorts();
var
boxTextures : GlTextureArray;
boxLength, i : Integer;
boxArray : TBoxArray;
temp : TBox;
begin
boxTextures := ogl.getTextures(11475);
boxLength := length(boxTextures);
for i := 0 to boxLength do
boxArray[i] := TBox(boxTextures[i].bounds);

self.pingBox := boxArray[boxLength-1];
if self.compareBoxes(boxArray[boxLength-1], boxArray[boxLength-2]) then
self.typeBox := boxArray[boxLength-4]
else if self.compareBoxes(boxArray[boxLength-2], boxArray[boxLength-3]) then
self.typeBox := boxArray[boxLength-4]
else
self.typeBox := boxArray[boxLength-3];


self.sortByType := (ogl.getTextures(10, self.typeBox).indexes() = 0);
self.sortByPing := (ogl.getTextures(10, self.pingBox).indexes() = 0);
writeln(sortByType, ' ', sortByPing);
end;

function tlobby.compareBoxes(box1, box2 : TBox): boolean;
begin
if (box1.x1 = box2.x1) and (box1.x2 = box2.x2) and
(box1.y1 = box2.y1) and (box1.y2 = box2.y2) then
result := true
else
result := false;
end;

And here is the error:
12:29:38 | debugTextureHighlight > setup
ERROR comes from a non-existing file (!addGlobalType)
Error: Access violation at line 1
Execution failed.
The following bitmaps were not freed: [0]

Keep in mind I ran it from another file so the access violation is from the first file.

3Garrett3
07-20-2015, 05:43 PM
It seems that you haven't considered the length of the box array at the start. These sorts of errors are usually caused by accessing array indices that don't exist. I'd throw a quick if length(X) < 5 then Exit into the function so that you aren't getting negative indices.

E: If that doesn't work then good luck, that's the only way I've ever seen the vague errors like this before.

Swag Bag
07-20-2015, 05:52 PM
That did it! I didn't have any textures found when I started it, so it was trying to get the bounds of nothing :)
EDIT: NEVERMIND 3Garrett3;! I added a check for box length, and that fixed part of it, and I checked that the .bounds returns a tbox, which it does. But it is still giving the error when I try to assign it to the BoxArray[0].
EDIT2: GOT IT! I had to set the length:setLength(boxArray, boxLength);


(sorry arrays I love you still)