From 3ce4b76b0db10fe878305ed1c8b84c6bb1ad4883 Mon Sep 17 00:00:00 2001 From: agent-q Date: Sat, 21 May 2011 15:54:20 +0100 Subject: DS/SAGA: Due to what looks like a compiler bug, having one Common::Array template inside another causes the DS build to crash during Common::Array::resize(). The only fix I can find is to make the internal byte array a normal malloc'ed() buffer. This way, the code runs fine. Need to dig into the assembly output for this to find out what's truly going on with the original code. --- engines/saga/font.cpp | 36 +++++++++++++++++++++++++++++++++++- engines/saga/font.h | 4 ++++ 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'engines/saga') diff --git a/engines/saga/font.cpp b/engines/saga/font.cpp index 2434f7aad8..60e7c98e7a 100644 --- a/engines/saga/font.cpp +++ b/engines/saga/font.cpp @@ -43,14 +43,32 @@ Font::Font(SagaEngine *vm) : _vm(vm) { _fonts.resize(_vm->getFontsCount()); for (i = 0; i < _vm->getFontsCount(); i++) { +#ifdef __DS__ + _fonts[i].outline.font = NULL; + _fonts[i].normal.font = NULL; +#endif loadFont(&_fonts[i], _vm->getFontDescription(i)->fontResourceId); } + + _fontMapping = 0; } Font::~Font() { debug(8, "Font::~Font(): Freeing fonts."); + +#ifdef __DS__ + for (int i = 0; i < _vm->getFontsCount(); i++) { + if (_fonts[i].outline.font) { + free(_fonts[i].outline.font); + } + + if (_fonts[i].normal.font) { + free(_fonts[i].normal.font); + } + } +#endif } @@ -107,9 +125,17 @@ void Font::loadFont(FontData *font, uint32 fontResourceId) { error("Invalid font resource size"); } +#ifndef __DS__ font->normal.font.resize(fontResourceData.size() - FONT_DESCSIZE); memcpy(font->normal.font.getBuffer(), fontResourceData.getBuffer() + FONT_DESCSIZE, fontResourceData.size() - FONT_DESCSIZE); - +#else + if (font->normal.font) { + free(font->normal.font); + } + + font->normal.font = (byte *) malloc(fontResourceData.size() - FONT_DESCSIZE); + memcpy(font->normal.font, fontResourceData.getBuffer() + FONT_DESCSIZE, fontResourceData.size() - FONT_DESCSIZE); +#endif // Create outline font style createOutline(font); @@ -153,7 +179,15 @@ void Font::createOutline(FontData *font) { font->outline.header.rowLength = newRowLength; // Allocate new font representation storage +#ifdef __DS__ + if (font->outline.font) { + free(font->outline.font); + } + + font->outline.font = (byte *) calloc(newRowLength * font->outline.header.charHeight, 1); +#else font->outline.font.resize(newRowLength * font->outline.header.charHeight); +#endif // Generate outline font representation diff --git a/engines/saga/font.h b/engines/saga/font.h index 6f66545756..57e8278c46 100644 --- a/engines/saga/font.h +++ b/engines/saga/font.h @@ -120,7 +120,11 @@ struct FontCharEntry { struct FontStyle { FontHeader header; FontCharEntry fontCharEntry[256]; +#ifndef __DS__ ByteArray font; +#else + byte* font; +#endif }; struct FontData { -- cgit v1.2.3