Fixed Issue #128 caused by read from unaligned memory (undefined behavior? when running asmjs).

This commit is contained in:
Branimir Karadžić 2014-08-07 20:31:35 -07:00
parent 659feeec61
commit e42d878fe8

View file

@ -808,14 +808,14 @@ namespace bgfx
static void decodeOpcode(uint32_t _opcode, UniformType::Enum& _type, uint16_t& _loc, uint16_t& _num, uint16_t& _copy) static void decodeOpcode(uint32_t _opcode, UniformType::Enum& _type, uint16_t& _loc, uint16_t& _num, uint16_t& _copy)
{ {
const uint32_t type = (_opcode&CONSTANT_OPCODE_TYPE_MASK) >> CONSTANT_OPCODE_TYPE_SHIFT; const uint32_t type = (_opcode&CONSTANT_OPCODE_TYPE_MASK) >> CONSTANT_OPCODE_TYPE_SHIFT;
const uint32_t loc = (_opcode&CONSTANT_OPCODE_LOC_MASK) >> CONSTANT_OPCODE_LOC_SHIFT; const uint32_t loc = (_opcode&CONSTANT_OPCODE_LOC_MASK ) >> CONSTANT_OPCODE_LOC_SHIFT;
const uint32_t num = (_opcode&CONSTANT_OPCODE_NUM_MASK) >> CONSTANT_OPCODE_NUM_SHIFT; const uint32_t num = (_opcode&CONSTANT_OPCODE_NUM_MASK ) >> CONSTANT_OPCODE_NUM_SHIFT;
const uint32_t copy = (_opcode&CONSTANT_OPCODE_COPY_MASK) >> CONSTANT_OPCODE_COPY_SHIFT; const uint32_t copy = (_opcode&CONSTANT_OPCODE_COPY_MASK); // >> CONSTANT_OPCODE_COPY_SHIFT;
_type = (UniformType::Enum)(type); _type = (UniformType::Enum)(type);
_copy = (uint16_t)copy; _copy = (uint16_t)copy;
_num = (uint16_t)num; _num = (uint16_t)num;
_loc = (uint16_t)loc; _loc = (uint16_t)loc;
} }
void write(const void* _data, uint32_t _size) void write(const void* _data, uint32_t _size)
@ -844,8 +844,9 @@ namespace bgfx
uint32_t read() uint32_t read()
{ {
const char* result = read(sizeof(uint32_t) ); uint32_t result;
return *( (uint32_t*)result); memcpy(&result, read(sizeof(uint32_t) ), sizeof(uint32_t) );
return result;
} }
bool isEmpty() const bool isEmpty() const