While working on my latest AGI project, I came across a bug in AGI that I don't think anyone has ever mentioned before. I wanted to place a series of views in a line, directly adjacent to each other with no gaps between them. But when I first added them, AGI moved them around, using the 'shuffle' function that gets applied when screen objects are found to be overlapping.
Which made no sense to me; the objects were all exactly 16 pixels wide, and I positioned them exactly 16 pixels apart; that should align them all right next to each other. So why did AGI shuffle them?
I took a look at the code in the shuffle function and found that there is a bug in there that checks how objects overlap. When calculating the pixel value of the right edge of an object's baseline, the function adds the object's width to its position, which is actually one pixel PAST the right edge. It should decrement that value by one to get the actual position of the right edge. But it doesn't.
Because of this, AGI thinks objects overlap when they are placed adjacent to each other with the same Y value. And this bug exists in every MSDOS version of AGI, including all known v2 and all v3 interpreters.
Here is a graphical explanation to clarify:
Object A is 4 pixels wide with an X value of 4:
0 1
0123456789012345
....AAAA........
Add new object B, also width of 4, and position it with an X value of 9, with same Y value as object A. It will look like this:
0 1
0123456789012345
....AAAA.BBBB...
Then try to position object B right next to object A, by using X value of 8. You would expect to get this:
0 1
0123456789012345
....AAAABBBB....
but the shuffle function thinks this is an overlap, and will shuffle object B, which (because of how the shuffle function works) will actually give you this:
0 1
0123456789012345
....AAAA........
.......BBBB.....
The shuffle function is used to check object movement as well, so if two objects are at the same Y value, they can never be moved so they touch each other; AGI forces a one pixel gap between them because of this bug.
If either object is set to ignore objects, then overlapping is allowed, and placement/movement is not affected. But that doesn't help if you can't use the ignore.objs command for other reasons.
I checked around, and I haven't seen any mention of this anywhere. I haven't seen any posts asking about this behavior, and there's nothing in any AGI documentation (Specs, help files, etc.)
It's surprising to me that after all these years, there are still new things to discover within the AGI code.