From 5a8be4de4b1e7d9ba4f926efd25ee929310e93bf Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Fri, 15 May 2020 21:04:36 +0200 Subject: [PATCH] Fix -Wclass-memaccess warnings --- .../src/RenderableParticleEffectEntityItem.cpp | 2 +- libraries/gpu-gl-common/src/gpu/gl/GLBackend.h | 6 +++--- .../gpu-gl-common/src/gpu/gl/GLBackendState.cpp | 3 +-- .../src/gpu/gl/GLBackendTransform.cpp | 4 ++-- libraries/octree/src/OctreePacketData.cpp | 14 ++++++++++---- libraries/shared/src/BufferParser.h | 6 +++++- libraries/shared/src/GeometryUtil.cpp | 4 +++- libraries/shared/src/shared/ConicalViewFrustum.cpp | 5 +++-- 8 files changed, 28 insertions(+), 16 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index bc56781924..5fafc0ab99 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -146,7 +146,7 @@ void ParticleEffectEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEn particleUniforms.rotateWithEntity = _particleProperties.rotateWithEntity ? 1 : 0; }); // Update particle uniforms - memcpy(&_uniformBuffer.edit(), &particleUniforms, sizeof(ParticleUniforms)); + _uniformBuffer.edit() = particleUniforms; } ItemKey ParticleEffectEntityRenderer::getKey() { diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h index 2532de31b0..a13718f5a2 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h @@ -378,10 +378,10 @@ protected: TransformCamera _cams[2]; Cameras(){}; - Cameras(const TransformCamera& cam) { memcpy(_cams, &cam, sizeof(TransformCamera)); }; + Cameras(const TransformCamera& cam) { _cams[0] = cam; }; Cameras(const TransformCamera& camL, const TransformCamera& camR) { - memcpy(_cams, &camL, sizeof(TransformCamera)); - memcpy(_cams + 1, &camR, sizeof(TransformCamera)); + _cams[0] = camL; + _cams[1] = camR; }; }; diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendState.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendState.cpp index 0c2c0ae744..c939b734dd 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendState.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendState.cpp @@ -331,8 +331,7 @@ void GLBackend::do_setStateBlendFactor(const Batch& batch, size_t paramOffset) { void GLBackend::do_setStateScissorRect(const Batch& batch, size_t paramOffset) { Vec4i rect; - memcpy(&rect, batch.readData(batch._params[paramOffset]._uint), sizeof(Vec4i)); - + memcpy(glm::value_ptr(rect), batch.readData(batch._params[paramOffset]._uint), sizeof(Vec4i)); if (_stereo.isStereo()) { rect.z /= 2; if (_stereo._pass) { diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp index 555a0a1e41..67ab502b6b 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp @@ -24,7 +24,7 @@ void GLBackend::do_setViewTransform(const Batch& batch, size_t paramOffset) { } void GLBackend::do_setProjectionTransform(const Batch& batch, size_t paramOffset) { - memcpy(&_transform._projection, batch.readData(batch._params[paramOffset]._uint), sizeof(Mat4)); + memcpy(glm::value_ptr(_transform._projection), batch.readData(batch._params[paramOffset]._uint), sizeof(Mat4)); _transform._invalidProj = true; } @@ -35,7 +35,7 @@ void GLBackend::do_setProjectionJitter(const Batch& batch, size_t paramOffset) { } void GLBackend::do_setViewportTransform(const Batch& batch, size_t paramOffset) { - memcpy(&_transform._viewport, batch.readData(batch._params[paramOffset]._uint), sizeof(Vec4i)); + memcpy(glm::value_ptr(_transform._viewport), batch.readData(batch._params[paramOffset]._uint), sizeof(Vec4i)); #ifdef GPU_STEREO_DRAWCALL_INSTANCED { diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 5e6825c886..3966fcf86f 100755 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -16,6 +16,7 @@ #include "OctreeLogging.h" #include "NumericalConstants.h" +#include bool OctreePacketData::_debug = false; AtomicUIntStat OctreePacketData::_totalBytesOfOctalCodes { 0 }; @@ -702,17 +703,17 @@ void OctreePacketData::debugBytes() { } int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, glm::vec2& result) { - memcpy(&result, dataBytes, sizeof(result)); + memcpy(glm::value_ptr(result), dataBytes, sizeof(result)); return sizeof(result); } int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, glm::vec3& result) { - memcpy(&result, dataBytes, sizeof(result)); + memcpy(glm::value_ptr(result), dataBytes, sizeof(result)); return sizeof(result); } int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, glm::u8vec3& result) { - memcpy(&result, dataBytes, sizeof(result)); + memcpy(glm::value_ptr(result), dataBytes, sizeof(result)); return sizeof(result); } @@ -743,7 +744,12 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVecto memcpy(&length, dataBytes, sizeof(uint16_t)); dataBytes += sizeof(length); result.resize(length); - memcpy(result.data(), dataBytes, length * sizeof(glm::vec3)); + + for(int i=0;i class BufferParser { public: @@ -98,7 +99,10 @@ template<> inline void BufferParser::readValue(QVector& result) { uint16_t length; readValue(length); result.resize(length); - memcpy(result.data(), _data + _offset, sizeof(glm::vec3) * length); + for(int i=0;i void ConicalViewFrustum::set(const ViewFrustum& viewFrustum) { // The ConicalViewFrustum has two parts: a central sphere (same as ViewFrustum) and a circular cone that bounds the frustum part. @@ -131,9 +132,9 @@ int ConicalViewFrustum::serialize(unsigned char* destinationBuffer) const { int ConicalViewFrustum::deserialize(const unsigned char* sourceBuffer) { const unsigned char* startPosition = sourceBuffer; - memcpy(&_position, sourceBuffer, sizeof(_position)); + memcpy(glm::value_ptr(_position), sourceBuffer, sizeof(_position)); sourceBuffer += sizeof(_position); - memcpy(&_direction, sourceBuffer, sizeof(_direction)); + memcpy(glm::value_ptr(_direction), sourceBuffer, sizeof(_direction)); sourceBuffer += sizeof(_direction); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &_angle); sourceBuffer += unpackClipValueFromTwoByte(sourceBuffer, _farClip);