Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Source/Amiga/Graphics_Amiga2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ void cGraphics_Amiga2::Map_Load_Resources() {
mSpriteSheet_InGame2.mDimension.mHeight = 0x151;
mSpriteSheet_InGame1.mDimension.mHeight = 0x150;

auto ValidateRawSize = [](sImage& pImage) {
const size_t RowStrideBytes = pImage.mDimension.mWidth >> 3;
const size_t RequiredBytes = RowStrideBytes * pImage.mDimension.mHeight * pImage.mPlanes;

if (pImage.mData->size() < RequiredBytes)
pImage = sImage();
};

ValidateRawSize(mSpriteSheet_InGame2);
ValidateRawSize(mSpriteSheet_InGame1);

SetActiveSpriteSheet(eGFX_IN_GAME);
}

Expand Down Expand Up @@ -142,6 +153,11 @@ sImage cGraphics_Amiga2::GetImage(const std::string& pFilename, const size_t pPa
Decoded.mDimension.mWidth = 0x140;
Decoded.mDimension.mHeight = 0x100;

const size_t RowStrideBytes = Decoded.mDimension.mWidth >> 3;
const size_t RequiredBytes = RowStrideBytes * Decoded.mDimension.mHeight * Decoded.mPlanes;
if (Decoded.mData->size() < RequiredBytes)
return sImage();

Decoded.LoadPalette_Amiga((uint8*)Palette->data(), Palette->size() / 2, pPaletteIndex);

return Decoded;
Expand Down Expand Up @@ -221,4 +237,4 @@ void cGraphics_Amiga2::Recruit_Draw_Hill() {
}

Recruit_Draw_HomeAway();
}
}
8 changes: 7 additions & 1 deletion Source/Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ struct sImage {
void LoadPalette_Amiga( const uint8 *pFrom, const size_t pCount, const size_t pStartColorID = 0 ) {

uint16 color;
const size_t PaletteLimit = sizeof(mPalette) / sizeof(mPalette[0]);

for (size_t ColorID = pStartColorID; ColorID < pStartColorID + pCount; ColorID++) {
if (pStartColorID >= PaletteLimit)
return;

const size_t ColorsToRead = std::min(pCount, PaletteLimit - pStartColorID);

for (size_t ColorID = pStartColorID; ColorID < pStartColorID + ColorsToRead; ColorID++) {

// Get the next color codes
color = readBEWord(pFrom);
Expand Down
Loading