emscripten-ports / SDL2_net

Other
6 stars 4 forks source link

SDLNet_Read16() and SDLNet_Read32() only works when aligned #2

Open jsaak opened 8 years ago

jsaak commented 8 years ago
char buffer[128];
Uint16 good = SDLNet_Read16(buff+2);
Uint16 wrong = SDLNet_Read16(buff+3);

when not aligned, then they use invalid bytes

jsaak commented 8 years ago

compiling with -DSDL_DATA_ALIGNED=1 does work, but this is a workaround a proper fix is needed

jbaicoianu commented 8 years ago

Is this something that affects SDL2_net natively as well, or is this bug specific to the Emscripten port?

jsaak commented 8 years ago

Emscripten port only i think

from SDL_net.h

/* Warning, some systems have data access alignment restrictions */
#if defined(sparc) || defined(mips) || defined(__arm__)
#define SDL_DATA_ALIGNED    1
#endif
#ifndef SDL_DATA_ALIGNED
#define SDL_DATA_ALIGNED    0
#endif