Arduino_GFX icon indicating copy to clipboard operation
Arduino_GFX copied to clipboard

print() doesn't work with custom GFX class

Open Spongman opened this issue 1 year ago • 1 comments

going to try again, since the previous issue was wrongly closed. this version has override keywords because ... reasons?

v1.4.4 on rp2040, arduino, platformio.

#include <Arduino_GFX_Library.h>

void setup()
{
	class MyGFX : public Arduino_GFX
	{
		int foo;

	public:
		MyGFX(int16_t w, int16_t h) : Arduino_GFX(w, h)
		{
		}

		bool begin(int32_t speed = GFX_NOT_DEFINED) override { return true; }

		void writePixelPreclipped(int16_t x, int16_t y, uint16_t color) override
		{
			Serial.printf("writePixelPreclipped %i, %i, %x\n", x, y, color);
		}
	};

	MyGFX buffer(240, 135);

	Serial.println(F("start"));
	buffer.startWrite();

	buffer.drawPixel(0, 0, RGB565(255, 255, 0));

	buffer.setCursor(10, 10);
	buffer.setTextColor(RGB565_GREEN);
	buffer.print("text");

	buffer.endWrite();
	Serial.println(F("done"));
}

for some reason, buffer.print() isn't doing anything, and I can't tell why. all i get is

start
writePixelPreclipped 0, 0, ffe0
done

If I comment out the int foo; line, then it works:

start
writePixelPreclipped 0, 0, ffe0
writePixelPreclipped 10, 12, 7e0
writePixelPreclipped 11, 12, 7e0
writePixelPreclipped 12, 10, 7e0
writePixelPreclipped 12, 11, 7e0
writePixelPreclipped 12, 12, 7e0
...

Spongman avatar Feb 13 '24 02:02 Spongman

ok, the cause of the bug (that has nothing to do with the override keyword, btw) is that the _(min|max)_text_(x|y) fields are uninitialized, and have predictable but undefined values. the commenting/uncommenting of the line of code was a red-herring, it just resulted in different codegen and a different set of undefined values for the uninitialized fields.

Spongman avatar Feb 13 '24 03:02 Spongman

How to implement a new class is a discussion, so it converted to discussion. Please do not try to raise duplicate discussion in issue again.

moononournation avatar Feb 22 '24 14:02 moononournation

this bug has nothing to do with "implement a new class". the bug is that the min/max text fields are uninitialized.

it seems very strange to me that you're unable to acknowledge the true cause of this issue, and persist in telling me that I don't know how to code c++, when clearly it is you that is mistaken about how the override keyword works.

not only did i demonstrate to you that you are mistaken about the C++ language, I went ahead and found the actual cause of the bug and submitted a pull-request fixing the issue.

the reason I opened a duplicate issue, is because it was actually an issue (as demonstrated by me providing a fix for it), and the first issue was incorrectly closed and locked.

please take care to read and understand issues that people raise before closing them out of hand. doing so incorrectly can come across as rude, honestly.

Spongman avatar Feb 26 '24 08:02 Spongman

If it is a bug, the issue should report all child class print() doesn't work, right? The override keyword just my previous experience about the unexpected behavior of some child classes. As you may already found, the hobbyist level coder may not give you the answer as accurate as ChatGPT. Sorry for I cannot be one of your guider in your coding journey. As mentioned in the library main page, I have very limited time that only can focus on the actual bugs the public suffering and my preferred enhancements.

moononournation avatar Mar 03 '24 06:03 moononournation