mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 17:01:06 +02:00
Merge pull request #13113 from sethalves/fix-ktx-asan-warning
avoid misaligned pointer deref in ktx code
This commit is contained in:
commit
14f4c035ab
1 changed files with 10 additions and 7 deletions
|
@ -46,13 +46,14 @@ struct GPUKTXPayload {
|
||||||
|
|
||||||
memcpy(data, &_samplerDesc, sizeof(Sampler::Desc));
|
memcpy(data, &_samplerDesc, sizeof(Sampler::Desc));
|
||||||
data += sizeof(Sampler::Desc);
|
data += sizeof(Sampler::Desc);
|
||||||
|
|
||||||
// We can't copy the bitset in Texture::Usage in a crossplateform manner
|
// We can't copy the bitset in Texture::Usage in a crossplateform manner
|
||||||
// So serialize it manually
|
// So serialize it manually
|
||||||
*(uint32*)data = _usage._flags.to_ulong();
|
uint32 usageData = _usage._flags.to_ulong();
|
||||||
|
memcpy(data, &usageData, sizeof(uint32));
|
||||||
data += sizeof(uint32);
|
data += sizeof(uint32);
|
||||||
|
|
||||||
*(TextureUsageType*)data = _usageType;
|
memcpy(data, &_usageType, sizeof(TextureUsageType));
|
||||||
data += sizeof(TextureUsageType);
|
data += sizeof(TextureUsageType);
|
||||||
|
|
||||||
return data + PADDING;
|
return data + PADDING;
|
||||||
|
@ -77,13 +78,15 @@ struct GPUKTXPayload {
|
||||||
|
|
||||||
memcpy(&_samplerDesc, data, sizeof(Sampler::Desc));
|
memcpy(&_samplerDesc, data, sizeof(Sampler::Desc));
|
||||||
data += sizeof(Sampler::Desc);
|
data += sizeof(Sampler::Desc);
|
||||||
|
|
||||||
// We can't copy the bitset in Texture::Usage in a crossplateform manner
|
// We can't copy the bitset in Texture::Usage in a crossplateform manner
|
||||||
// So unserialize it manually
|
// So unserialize it manually
|
||||||
_usage = Texture::Usage(*(const uint32*)data);
|
uint32 usageData;
|
||||||
|
memcpy(&usageData, data, sizeof(uint32));
|
||||||
|
_usage = Texture::Usage(usageData);
|
||||||
data += sizeof(uint32);
|
data += sizeof(uint32);
|
||||||
|
|
||||||
_usageType = *(const TextureUsageType*)data;
|
memcpy(&_usageType, data, sizeof(TextureUsageType));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,4 +713,4 @@ bool Texture::evalTextureFormat(const ktx::Header& header, Element& mipFormat, E
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue