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

@ -810,7 +810,7 @@ namespace bgfx
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;
@ -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