Ensure that fonts for hires bitmaps get deleted.

This commit is contained in:
Wayward Heart 2024-06-02 00:38:45 -05:00
parent 65aab17dba
commit 477162d1d3
2 changed files with 14 additions and 5 deletions

View file

@ -46,7 +46,6 @@ void bitmapInitProps(Bitmap *b, VALUE self) {
rb_obj_call_init(fontObj, 0, 0); rb_obj_call_init(fontObj, 0, 0);
Font *font = getPrivateData<Font>(fontObj); Font *font = getPrivateData<Font>(fontObj);
b->setInitFont(font);
rb_iv_set(self, "font", fontObj); rb_iv_set(self, "font", fontObj);
@ -54,7 +53,15 @@ void bitmapInitProps(Bitmap *b, VALUE self) {
if (b->hasHires()) { if (b->hasHires()) {
b->assumeRubyGC(); b->assumeRubyGC();
wrapProperty(self, b->getHires(), "hires", BitmapType); wrapProperty(self, b->getHires(), "hires", BitmapType);
VALUE hiresFontObj = rb_obj_alloc(fontKlass);
rb_obj_call_init(hiresFontObj, 0, 0);
Font *hiresFont = getPrivateData<Font>(hiresFontObj);
rb_iv_set(rb_iv_get(self, "hires"), "font", hiresFontObj);
b->getHires()->setInitFont(hiresFont);
} }
b->setInitFont(font);
} }
RB_METHOD(bitmapInitialize) { RB_METHOD(bitmapInitialize) {

View file

@ -2220,10 +2220,12 @@ void Bitmap::setFont(Font &value)
void Bitmap::setInitFont(Font *value) void Bitmap::setInitFont(Font *value)
{ {
if (hasHires()) { if (hasHires()) {
Font *hiresFont = new Font(*value); Font *hiresFont = p->selfHires->p->font;
// Disable the illegal font size check when creating a high-res font. if (hiresFont && hiresFont != &shState->defaultFont())
hiresFont->setSize(hiresFont->getSize() * p->selfHires->width() / width(), false); {
p->selfHires->setInitFont(hiresFont); // Disable the illegal font size check when creating a high-res font.
hiresFont->setSize(hiresFont->getSize() * p->selfHires->width() / width(), false);
}
} }
p->font = value; p->font = value;