Browse Source

ref_gl: fix unaligned access in sprites

pull/2/head
Alibek Omarov 6 years ago
parent
commit
55c3040db1
  1. 23
      ref_gl/gl_sprite.c

23
ref_gl/gl_sprite.c

@ -53,13 +53,14 @@ upload a single frame
*/ */
static const dframetype_t *R_SpriteLoadFrame( model_t *mod, const void *pin, mspriteframe_t **ppframe, int num ) static const dframetype_t *R_SpriteLoadFrame( model_t *mod, const void *pin, mspriteframe_t **ppframe, int num )
{ {
const dspriteframe_t *pinframe; const dspriteframe_t pinframe;
mspriteframe_t *pspriteframe; mspriteframe_t *pspriteframe;
int gl_texturenum = 0; int gl_texturenum = 0;
char texname[128]; char texname[128];
int bytes = 1; int bytes = 1;
pinframe = (dspriteframe_t *)pin; memcpy( &pinframe, pin, sizeof(dspriteframe_t));
if( sprite_version == SPRITE_VERSION_32 ) if( sprite_version == SPRITE_VERSION_32 )
bytes = 4; bytes = 4;
@ -67,26 +68,26 @@ static const dframetype_t *R_SpriteLoadFrame( model_t *mod, const void *pin, msp
if( FBitSet( mod->flags, MODEL_CLIENT )) // it's a HUD sprite if( FBitSet( mod->flags, MODEL_CLIENT )) // it's a HUD sprite
{ {
Q_snprintf( texname, sizeof( texname ), "#HUD/%s(%s:%i%i).spr", sprite_name, group_suffix, num / 10, num % 10 ); Q_snprintf( texname, sizeof( texname ), "#HUD/%s(%s:%i%i).spr", sprite_name, group_suffix, num / 10, num % 10 );
gl_texturenum = GL_LoadTexture( texname, pin, pinframe->width * pinframe->height * bytes, r_texFlags ); gl_texturenum = GL_LoadTexture( texname, pin, pinframe.width * pinframe.height * bytes, r_texFlags );
} }
else else
{ {
Q_snprintf( texname, sizeof( texname ), "#%s(%s:%i%i).spr", sprite_name, group_suffix, num / 10, num % 10 ); Q_snprintf( texname, sizeof( texname ), "#%s(%s:%i%i).spr", sprite_name, group_suffix, num / 10, num % 10 );
gl_texturenum = GL_LoadTexture( texname, pin, pinframe->width * pinframe->height * bytes, r_texFlags ); gl_texturenum = GL_LoadTexture( texname, pin, pinframe.width * pinframe.height * bytes, r_texFlags );
} }
// setup frame description // setup frame description
pspriteframe = Mem_Malloc( mod->mempool, sizeof( mspriteframe_t )); pspriteframe = Mem_Malloc( mod->mempool, sizeof( mspriteframe_t ));
pspriteframe->width = pinframe->width; pspriteframe->width = pinframe.width;
pspriteframe->height = pinframe->height; pspriteframe->height = pinframe.height;
pspriteframe->up = pinframe->origin[1]; pspriteframe->up = pinframe.origin[1];
pspriteframe->left = pinframe->origin[0]; pspriteframe->left = pinframe.origin[0];
pspriteframe->down = pinframe->origin[1] - pinframe->height; pspriteframe->down = pinframe.origin[1] - pinframe.height;
pspriteframe->right = pinframe->width + pinframe->origin[0]; pspriteframe->right = pinframe.width + pinframe.origin[0];
pspriteframe->gl_texturenum = gl_texturenum; pspriteframe->gl_texturenum = gl_texturenum;
*ppframe = pspriteframe; *ppframe = pspriteframe;
return (dframetype_t *)((byte *)(pinframe + 1) + pinframe->width * pinframe->height * bytes ); return ( pin + sizeof(dspriteframe_t) + pinframe.width * pinframe.height * bytes );
} }
/* /*

Loading…
Cancel
Save