force data in MemoryStorage to be word aligned to avoid crash in glTextureSubImage2D

This commit is contained in:
Seth Alves 2017-05-10 18:14:50 -07:00
parent 3c652a52d8
commit c9868640c1
4 changed files with 13 additions and 9 deletions

View file

@ -14,7 +14,7 @@
class OtherAvatar : public Avatar {
public:
explicit OtherAvatar(QThread* thread, RigPointer rig = nullptr);
void instantiableAvatar() {};
virtual void instantiableAvatar() override {};
};
#endif // hifi_OtherAvatar_h

View file

@ -71,7 +71,7 @@ public:
void addSample(T sample) {
if (numSamples > 0) {
average = (sample * WEIGHTING) + (average * ONE_MINUS_WEIGHTING);
average = (sample * (T)WEIGHTING) + (average * (T)ONE_MINUS_WEIGHTING);
} else {
average = sample;
}

View file

@ -38,8 +38,9 @@ StoragePointer Storage::toFileStorage(const QString& filename) const {
return FileStorage::create(filename, size(), data());
}
MemoryStorage::MemoryStorage(size_t size, const uint8_t* data) {
_data.resize(size);
MemoryStorage::MemoryStorage(size_t size, const uint8_t* data) : _size(size) {
_data.resize((size + 3) / 4); // alloc smallest number of 4-byte chunks that will cover size bytes
if (data) {
memcpy(_data.data(), data, size);
}

View file

@ -41,13 +41,16 @@ namespace storage {
class MemoryStorage : public Storage {
public:
MemoryStorage(size_t size, const uint8_t* data = nullptr);
const uint8_t* data() const override { return _data.data(); }
uint8_t* data() { return _data.data(); }
uint8_t* mutableData() override { return _data.data(); }
size_t size() const override { return _data.size(); }
const uint8_t* data() const override { return reinterpret_cast<const uint8_t*>(_data.data()); }
uint8_t* data() { return reinterpret_cast<uint8_t*>(_data.data()); }
uint8_t* mutableData() override { return reinterpret_cast<uint8_t*>(_data.data()); }
size_t _size { 0 };
size_t size() const override { return _size; }
operator bool() const override { return true; }
private:
std::vector<uint8_t> _data;
// the vector is of uint32_t rather than uint8_t to force alignment
std::vector<uint32_t> _data;
};
class FileStorage : public Storage {