GFX: problems with triangles

I'm using a tft with 320x480 resolution and mcufriend libraries with adafruit gfx.
with rotation (0) the triangles with the following vertices:
y1 = 236
x1 = 0
y2 = 96
x2 = 0
y3 = 288
x3 = 320
with the "empty" triangle (drawTriangle) everything is fine, but if I use the "full" triangle (fillTriangle) the image is completely wrong because?

add the photo fill triangle

Ah-ha. I am surprised that this has not appeared before !

#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

int y1 = 236;
int x1 = 0;
int y2 = 96;
int x2 = 0;
int y3 = 288;
int x3 = 320;

void setup()
{
    tft.begin(tft.readID());
    tft.setRotation(1);
}

void loop()
{
    tft.fillScreen(TFT_WHITE);
    tft.drawTriangle(x1, y1, x2, y2, x3, y3, TFT_BLUE);
    delay(1000);
    tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_RED);
    delay(1000);
}

The problem is intermediate overflow in the Adafruit_GFX.cpp
This should fix it.

    // For lower part of triangle, find scanline crossings for segments
    // 0-2 and 1-2.  This loop is skipped if y1=y2.
    sa = (int32_t)dx12 * (y - y1);
    sb = (int32_t)dx02 * (y - y0);

David.

thank you.
It works
If you have time and want to tell me what you mean by intermediate overflow.

I have reported this on the GitHub page as an "Issue" rather than as a "Pull Request".
(I have never Forked Adafruit_GFX)

I am surprised that this has never come up before.
I do remember the first 320x480 screens failing on the "Adafruit Tests".
And fixing the original Adafruit_GFX for fillTriangle() by making sa, sb int32_t instead of int16_t

David.

For future reference, Adafruit has merged the PR so David’s fix is now available in the latest official Adafruit-GFX release (1.4.14).