Skip to content

Commit

Permalink
DS/SAGA: Due to what looks like a compiler bug, having one Common::Ar…
Browse files Browse the repository at this point in the history
…ray 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.
  • Loading branch information
agent-q committed May 21, 2011
1 parent 6fdec4d commit 3ce4b76
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
36 changes: 35 additions & 1 deletion engines/saga/font.cpp
Expand Up @@ -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
}


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions engines/saga/font.h
Expand Up @@ -120,7 +120,11 @@ struct FontCharEntry {
struct FontStyle {
FontHeader header;
FontCharEntry fontCharEntry[256];
#ifndef __DS__
ByteArray font;
#else
byte* font;
#endif
};

struct FontData {
Expand Down

0 comments on commit 3ce4b76

Please sign in to comment.