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.

This commit is contained in:
agent-q 2011-05-21 15:54:20 +01:00
parent 6fdec4dfac
commit 3ce4b76b0d
2 changed files with 39 additions and 1 deletions

View File

@ -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

View File

@ -120,7 +120,11 @@ struct FontCharEntry {
struct FontStyle {
FontHeader header;
FontCharEntry fontCharEntry[256];
#ifndef __DS__
ByteArray font;
#else
byte* font;
#endif
};
struct FontData {