From 4393ef1bd5c607df678d78b56dd9c1e515dae84f Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Thu, 9 Dec 2010 21:25:21 +0000 Subject: MOHAWK: Fix LBPaletteItem to handle variable-size palettes svn-id: r54846 --- engines/mohawk/livingbooks.cpp | 17 +++++++++++++++-- engines/mohawk/livingbooks.h | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp index e750e2c2f2..6d93ec4151 100644 --- a/engines/mohawk/livingbooks.cpp +++ b/engines/mohawk/livingbooks.cpp @@ -2692,19 +2692,29 @@ void LBGroupItem::stop() { LBPaletteItem::LBPaletteItem(MohawkEngine_LivingBooks *vm, Common::Rect rect) : LBItem(vm, rect) { debug(3, "new LBPaletteItem"); + _fadeInStart = 0; + _palette = NULL; +} + +LBPaletteItem::~LBPaletteItem() { + delete[] _palette; } void LBPaletteItem::readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream) { switch (type) { case kLBPaletteXData: { - assert(size == 8 + 255 * 4); + assert(size >= 8); _fadeInPeriod = stream->readUint16(); _fadeInStep = stream->readUint16(); _drawStart = stream->readUint16(); _drawCount = stream->readUint16(); - stream->read(_palette, 255 * 4); + if (_drawStart + _drawCount > 256) + error("encountered palette trying to set more than 256 colours"); + assert(size == 8 + _drawCount * 4); + _palette = new byte[_drawCount * 4]; + stream->read(_palette, _drawCount * 4); } break; @@ -2728,6 +2738,9 @@ bool LBPaletteItem::togglePlaying(bool playing, bool restart) { void LBPaletteItem::update() { if (_fadeInStart) { + if (!_palette) + error("LBPaletteItem had no palette on startup"); + uint32 elapsedTime = _vm->_system->getMillis() - _fadeInStart; uint32 divTime = elapsedTime / _fadeInStep; diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index fe4c47dc48..b1879824ad 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -419,6 +419,7 @@ protected: class LBPaletteItem : public LBItem { public: LBPaletteItem(MohawkEngine_LivingBooks *_vm, Common::Rect rect); + ~LBPaletteItem(); void readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream); @@ -428,7 +429,7 @@ public: protected: uint16 _fadeInPeriod, _fadeInStep, _drawStart, _drawCount; uint32 _fadeInStart, _fadeInCurrent; - byte _palette[255 * 4]; + byte *_palette; }; struct LiveTextWord { -- cgit v1.2.3