From 23f60da40df419b2105a482e1c2031438bfb72e3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 22 Aug 2024 20:24:52 +0200 Subject: [PATCH] Fix various code issues found using PVS-Studio --- .../Animations/SceneAnimations/SceneAnimationPlayer.cpp | 2 +- Source/Engine/Core/Collections/Array.h | 7 +++++++ Source/Engine/Core/Collections/ChunkedArray.h | 8 ++++++++ Source/Engine/Core/Collections/Dictionary.h | 7 +++++++ Source/Engine/Core/Collections/HashSet.h | 7 +++++++ Source/Engine/Core/Types/DataContainer.h | 2 +- Source/Engine/Core/Types/StringView.h | 6 ++++++ Source/Engine/Particles/Particles.cpp | 6 +++--- Source/Engine/Render2D/Render2D.cpp | 2 +- Source/Engine/Scripting/ScriptingType.h | 6 ++++++ Source/Engine/Terrain/TerrainPatch.cpp | 3 ++- 11 files changed, 49 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp b/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp index ce23b92a4..a06150875 100644 --- a/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp +++ b/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp @@ -92,7 +92,7 @@ void SceneAnimationPlayer::Pause() if (_state != PlayState::Playing) return; - if (IsActiveInHierarchy() && _state == PlayState::Playing) + if (IsActiveInHierarchy()) { UNREGISTER_TICK; } diff --git a/Source/Engine/Core/Collections/Array.h b/Source/Engine/Core/Collections/Array.h index 7281fa8d8..a17d8f686 100644 --- a/Source/Engine/Core/Collections/Array.h +++ b/Source/Engine/Core/Collections/Array.h @@ -1027,6 +1027,13 @@ public: return *this; } + Iterator& operator=(Iterator&& v) + { + _array = v._array; + _index = v._index; + return *this; + } + Iterator& operator++() { if (_index != _array->_count) diff --git a/Source/Engine/Core/Collections/ChunkedArray.h b/Source/Engine/Core/Collections/ChunkedArray.h index 157efcd0f..457778b26 100644 --- a/Source/Engine/Core/Collections/ChunkedArray.h +++ b/Source/Engine/Core/Collections/ChunkedArray.h @@ -173,6 +173,14 @@ public: return *this; } + Iterator& operator=(Iterator&& v) + { + _collection = v._collection; + _chunkIndex = v._chunkIndex; + _index = v._index; + return *this; + } + Iterator& operator++() { // Check if it is not at end diff --git a/Source/Engine/Core/Collections/Dictionary.h b/Source/Engine/Core/Collections/Dictionary.h index 7c180e56e..9e516dae7 100644 --- a/Source/Engine/Core/Collections/Dictionary.h +++ b/Source/Engine/Core/Collections/Dictionary.h @@ -348,6 +348,13 @@ public: return *this; } + Iterator& operator=(Iterator&& v) + { + _collection = v._collection; + _index = v._index; + return *this; + } + Iterator& operator++() { const int32 capacity = _collection->_size; diff --git a/Source/Engine/Core/Collections/HashSet.h b/Source/Engine/Core/Collections/HashSet.h index b76244860..4a310fef0 100644 --- a/Source/Engine/Core/Collections/HashSet.h +++ b/Source/Engine/Core/Collections/HashSet.h @@ -329,6 +329,13 @@ public: return *this; } + Iterator& operator=(Iterator&& v) + { + _collection = v._collection; + _index = v._index; + return *this; + } + Iterator& operator++() { const int32 capacity = _collection->_size; diff --git a/Source/Engine/Core/Types/DataContainer.h b/Source/Engine/Core/Types/DataContainer.h index 7893eb1ca..9d506b1eb 100644 --- a/Source/Engine/Core/Types/DataContainer.h +++ b/Source/Engine/Core/Types/DataContainer.h @@ -338,7 +338,7 @@ public: Platform::MemoryCopy(Base::_data, prev, prevLength * sizeof(T)); Platform::MemoryCopy(Base::_data + prevLength * sizeof(T), data, length * sizeof(T)); - if (_isAllocated && prev) + if (_isAllocated) Allocator::Free(prev); _isAllocated = true; } diff --git a/Source/Engine/Core/Types/StringView.h b/Source/Engine/Core/Types/StringView.h index 052bc1d54..365b2fa7f 100644 --- a/Source/Engine/Core/Types/StringView.h +++ b/Source/Engine/Core/Types/StringView.h @@ -28,6 +28,12 @@ protected: { } + StringViewBase(const StringViewBase& other) + : _data(other._data) + , _length(other._length) + { + } + public: typedef T CharType; diff --git a/Source/Engine/Particles/Particles.cpp b/Source/Engine/Particles/Particles.cpp index 66fc91cce..53c1ab4b1 100644 --- a/Source/Engine/Particles/Particles.cpp +++ b/Source/Engine/Particles/Particles.cpp @@ -289,9 +289,9 @@ void DrawEmitterCPU(RenderContext& renderContext, ParticleBuffer* buffer, DrawCa // Check if need to setup ribbon modules int32 ribbonModuleIndex = 0; int32 ribbonModulesDrawIndicesPos = 0; - int32 ribbonModulesDrawIndicesStart[PARTICLE_EMITTER_MAX_RIBBONS]; - int32 ribbonModulesDrawIndicesCount[PARTICLE_EMITTER_MAX_RIBBONS]; - int32 ribbonModulesSegmentCount[PARTICLE_EMITTER_MAX_RIBBONS]; + int32 ribbonModulesDrawIndicesStart[PARTICLE_EMITTER_MAX_RIBBONS] = {}; + int32 ribbonModulesDrawIndicesCount[PARTICLE_EMITTER_MAX_RIBBONS] = {}; + int32 ribbonModulesSegmentCount[PARTICLE_EMITTER_MAX_RIBBONS] = {}; if (emitter->Graph.RibbonRenderingModules.HasItems()) { // Prepare ribbon data diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index 84de6666d..3c3b5a106 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -481,7 +481,7 @@ bool CachedPSO::Init(GPUShader* shader, bool useDepth) // Create pipeline states GPUPipelineState::Description desc = GPUPipelineState::Description::DefaultFullscreenTriangle; - desc.DepthEnable = desc.DepthWriteEnable = useDepth; + desc.DepthEnable = useDepth; desc.DepthWriteEnable = false; desc.DepthClipEnable = false; desc.VS = shader->GetVS("VS"); diff --git a/Source/Engine/Scripting/ScriptingType.h b/Source/Engine/Scripting/ScriptingType.h index 17a844097..6294ecbd9 100644 --- a/Source/Engine/Scripting/ScriptingType.h +++ b/Source/Engine/Scripting/ScriptingType.h @@ -40,6 +40,12 @@ struct FLAXENGINE_API ScriptingTypeHandle { } + FORCE_INLINE ScriptingTypeHandle(ScriptingTypeHandle&& other) + : Module(other.Module) + , TypeIndex(other.TypeIndex) + { + } + ScriptingTypeHandle(const ScriptingTypeInitializer& initializer); FORCE_INLINE operator bool() const diff --git a/Source/Engine/Terrain/TerrainPatch.cpp b/Source/Engine/Terrain/TerrainPatch.cpp index 93269269a..10ce5ba6a 100644 --- a/Source/Engine/Terrain/TerrainPatch.cpp +++ b/Source/Engine/Terrain/TerrainPatch.cpp @@ -1215,7 +1215,8 @@ Color32* TerrainPatch::GetSplatMapData(int32 index) void TerrainPatch::ClearSplatMapCache() { PROFILE_CPU_NAMED("Terrain.ClearSplatMapCache"); - _cachedSplatMap->Clear(); + if (_cachedSplatMap) + _cachedSplatMap->Clear(); } void TerrainPatch::ClearCache()