Skip to content

Adafruit-GFX-Library - Possible solution for Adafruit_GFX constructor-related link issue #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

christianpatterson
Copy link

Declare Adafruit_GFX::drawPixel pure virtual so that the compiler
knows not to expect a definition of the method in this class. The
compiler appears to create the vtable with the first
non-constructor, non-pure virtual method so when this method is
the first non-constructor method in the class and it is not
declared pure virtual the linker fails to find the vtable for this
class.

Change the Adafruit_GFX::constructor method to a real constructor.

Declare Adafruit_GFX::drawPixel pure virtual so that the compiler
knows not to expect a definition of the method in this class. The
compiler appears to create the vtable with the first
non-constructor, non-pure virtual method so when this method is
the first non-constructor method in the class and it is not
declared pure virtual the linker fails to find the vtable for this
class.

Change the Adafruit_GFX::constructor method to a real constructor.
@AquaQuieta
Copy link

This is absolutely why you are having to call the constructor...just tried these changes here, and it works...but I guess Christian has already seen it. You should also note that to really do the inheritance properly (in c++ish fashion), you'll should update the constructors of all the sub-classes to take the width and height parameters. Something like this worked for me:

// Constructor for 16x32 panel:
RGBmatrixPanel::RGBmatrixPanel(
uint8_t a, uint8_t b, uint8_t c,
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf):Adafruit_GFX(32,16) {

init(8, a, b, c, sclk, latch, oe, dbuf);
}

But really, to be more "generalized" you should pass in the W/H values in the sub-class's constructor: something like:

// Constructor for 16x32 panel:
RGBmatrixPanel::RGBmatrixPanel(
uint16_t w, uint16_t h,
uint8_t a, uint8_t b, uint8_t c,
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf):Adafruit_GFX(w,h) {

init(8, a, b, c, sclk, latch, oe, dbuf);
}
And of course remove the explicit constructor call from the init function in RGBMatrixPanel. I imagine all the sub-classes would all need to be updated similarly. Anyway, just my 2 cents...hope it helps :)

@PaintYourDragon
Copy link
Contributor

This has been manually rolled into the latest update. Really appreciate your help with this one -- thanks!

ihakov2 added a commit to ihakov2/Adafruit-GFX-Library that referenced this pull request Oct 25, 2023
M-D-777 pushed a commit to M-D-777/Adafruit-GFX-Library that referenced this pull request Feb 6, 2025
Add option to get charBounds of UTF-8 glyphs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants