Fix misaligned pointers

(cherry picked from commit ceb8d298c2ae9a6000fa4d22e381085c6bf77cd6)
This commit is contained in:
James R 2019-11-07 16:29:58 -08:00
parent da2a640c6c
commit 437f7aa16d

View file

@ -198,7 +198,7 @@ static UINT8 *R_GenerateTexture(size_t texnum)
int x, x1, x2, i; int x, x1, x2, i;
size_t blocksize; size_t blocksize;
column_t *patchcol; column_t *patchcol;
UINT32 *colofs; UINT8 *colofs;
I_Assert(texnum <= (size_t)numtextures); I_Assert(texnum <= (size_t)numtextures);
texture = textures[texnum]; texture = textures[texnum];
@ -219,10 +219,10 @@ static UINT8 *R_GenerateTexture(size_t texnum)
// Check the patch for holes. // Check the patch for holes.
if (texture->width > SHORT(realpatch->width) || texture->height > SHORT(realpatch->height)) if (texture->width > SHORT(realpatch->width) || texture->height > SHORT(realpatch->height))
holey = true; holey = true;
colofs = (UINT32 *)realpatch->columnofs; colofs = (UINT8 *)realpatch->columnofs;
for (x = 0; x < texture->width && !holey; x++) for (x = 0; x < texture->width && !holey; x++)
{ {
column_t *col = (column_t *)((UINT8 *)realpatch + LONG(colofs[x])); column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2]));
INT32 topdelta, prevdelta = -1, y = 0; INT32 topdelta, prevdelta = -1, y = 0;
while (col->topdelta != 0xff) while (col->topdelta != 0xff)
{ {
@ -250,11 +250,11 @@ static UINT8 *R_GenerateTexture(size_t texnum)
texturememory += blocksize; texturememory += blocksize;
// use the patch's column lookup // use the patch's column lookup
colofs = (UINT32 *)(void *)(block + 8); colofs = (block + 8);
texturecolumnofs[texnum] = colofs; texturecolumnofs[texnum] = (UINT32 *)colofs;
blocktex = block; blocktex = block;
for (x = 0; x < texture->width; x++) for (x = 0; x < texture->width; x++)
colofs[x] = LONG(LONG(colofs[x]) + 3); *(UINT32 *)&colofs[x<<2] = LONG(LONG(*(UINT32 *)&colofs[x<<2]) + 3);
goto done; goto done;
} }
@ -270,8 +270,8 @@ static UINT8 *R_GenerateTexture(size_t texnum)
memset(block, 0xF7, blocksize+1); // Transparency hack memset(block, 0xF7, blocksize+1); // Transparency hack
// columns lookup table // columns lookup table
colofs = (UINT32 *)(void *)block; colofs = block;
texturecolumnofs[texnum] = colofs; texturecolumnofs[texnum] = (UINT32 *)colofs;
// texture data after the lookup table // texture data after the lookup table
blocktex = block + (texture->width*4); blocktex = block + (texture->width*4);
@ -296,8 +296,8 @@ static UINT8 *R_GenerateTexture(size_t texnum)
patchcol = (column_t *)((UINT8 *)realpatch + LONG(realpatch->columnofs[x-x1])); patchcol = (column_t *)((UINT8 *)realpatch + LONG(realpatch->columnofs[x-x1]));
// generate column ofset lookup // generate column ofset lookup
colofs[x] = LONG((x * texture->height) + (texture->width*4)); *(UINT32 *)&colofs[x<<2] = LONG((x * texture->height) + (texture->width*4));
R_DrawColumnInCache(patchcol, block + LONG(colofs[x]), patch->originy, texture->height); R_DrawColumnInCache(patchcol, block + LONG(*(UINT32 *)&colofs[x<<2]), patch->originy, texture->height);
} }
} }