From e6e2bb176b7fdd505ad0c5effd041ec5c29c8442 Mon Sep 17 00:00:00 2001 From: Matteo De Carlo Date: Mon, 22 Aug 2022 18:21:13 +0200 Subject: [PATCH] Compiler warnings fixes (part 1) (#523) * COMPILER WARNINGS: remove unused variables * stricter linux compiler options and define fixes * const char* for string constants * Always initialize struct EventArgs with some valid values and another possible use of initialized variable * revert library change --- Editor/Assets/Icon.c | 2 +- WickedEngine/BULLET/CMakeLists.txt | 2 +- WickedEngine/CMakeLists.txt | 13 ++++++++++++- WickedEngine/Utility/DirectXMath.h | 11 +---------- WickedEngine/wiFont.cpp | 8 +++----- WickedEngine/wiGUI.cpp | 9 ++------- WickedEngine/wiGUI.h | 20 ++++++++++---------- WickedEngine/wiGraphicsDevice_Vulkan.cpp | 3 --- WickedEngine/wiImage.cpp | 2 -- WickedEngine/wiInput.cpp | 3 --- WickedEngine/wiLua.cpp | 1 - WickedEngine/wiMath.cpp | 1 - WickedEngine/wiOcean.cpp | 2 -- WickedEngine/wiPhysics_Bullet.cpp | 1 - WickedEngine/wiRenderPath3D.cpp | 4 ---- WickedEngine/wiRenderer.cpp | 16 ---------------- WickedEngine/wiSDLInput.cpp | 1 + WickedEngine/wiScene.cpp | 3 +-- 18 files changed, 32 insertions(+), 70 deletions(-) diff --git a/Editor/Assets/Icon.c b/Editor/Assets/Icon.c index 6547aa86e..51e21f081 100644 --- a/Editor/Assets/Icon.c +++ b/Editor/Assets/Icon.c @@ -4,7 +4,7 @@ static const struct { uint width; uint height; uint bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */ - char *comment; + const char *comment; unsigned char pixel_data[64 * 64 * 4 + 1]; } gimp_image = { 64, 64, 4, diff --git a/WickedEngine/BULLET/CMakeLists.txt b/WickedEngine/BULLET/CMakeLists.txt index 605a3e0ef..341f1f3dc 100644 --- a/WickedEngine/BULLET/CMakeLists.txt +++ b/WickedEngine/BULLET/CMakeLists.txt @@ -452,7 +452,7 @@ add_library(Bullet STATIC ${Bullet_HEADERS_LinearMath} ) -target_include_directories(Bullet PUBLIC +target_include_directories(Bullet SYSTEM PUBLIC $ $ ) diff --git a/WickedEngine/CMakeLists.txt b/WickedEngine/CMakeLists.txt index 1d6523f7e..8c7f5c90b 100644 --- a/WickedEngine/CMakeLists.txt +++ b/WickedEngine/CMakeLists.txt @@ -211,7 +211,7 @@ add_library(${TARGET_NAME} ${WICKED_LIBRARY_TYPE} add_library(WickedEngine ALIAS ${TARGET_NAME}) set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${HEADER_FILES}") -target_include_directories(${TARGET_NAME} PUBLIC +target_include_directories(${TARGET_NAME} SYSTEM PUBLIC $ $ ) @@ -227,6 +227,8 @@ if (WIN32) UNICODE _UNICODE ) + target_compile_options(${TARGET_NAME} PRIVATE /W3) + set(LIBDXCOMPILER "dxcompiler.dll") else () # `ska::flat_hash_map` has issues on linux because of the hash function being identity @@ -240,6 +242,15 @@ else () ) set(WICKEDENGINE_STATIC_LIBRARIES ${WICKEDENGINE_STATIC_LIBRARIES} FAudio) + # add some warnings and set them as errors + # read more details here: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html + target_compile_options(${TARGET_NAME} PRIVATE + -Wuninitialized + -Wwrite-strings + -Winit-self + -Wreturn-type + -Werror) + target_link_libraries(${TARGET_NAME} PRIVATE dl) set(LIBDXCOMPILER "libdxcompiler.so") diff --git a/WickedEngine/Utility/DirectXMath.h b/WickedEngine/Utility/DirectXMath.h index d7cdaa5bd..89755e9a2 100644 --- a/WickedEngine/Utility/DirectXMath.h +++ b/WickedEngine/Utility/DirectXMath.h @@ -170,16 +170,7 @@ #ifdef _MSC_VER # include #else -# define _In_ -# define _In_reads_(n) -# define _In_reads_bytes_(n) -# define _Out_ -# define _Out_writes_(n) -# define _Out_writes_bytes_(n) -# define _Out_opt_ -# define _Success_(expr) -# define _Use_decl_annotations_ -# define _Analysis_assume_(expr) +#include "dxc/Support/WinAdapter.h" #endif #include diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index fe285b241..89f987f67 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -286,8 +286,6 @@ namespace wi::font AddFontStyle("Liberation Sans", liberation_sans, sizeof(liberation_sans)); } - GraphicsDevice* device = wi::graphics::GetDevice(); - RasterizerState rs; rs.fill_mode = FillMode::SOLID; rs.cull_mode = CullMode::NONE; @@ -423,9 +421,9 @@ namespace wi::font rect.h -= 2; const int32_t hash = rect.id; - const wchar_t code = codefromhash(hash); - const int style = stylefromhash(hash); - const float height = (float)heightfromhash(hash); + //const wchar_t code = codefromhash(hash); + //const int style = stylefromhash(hash); + //const float height = (float)heightfromhash(hash); Glyph& glyph = glyph_lookup[hash]; Bitmap& bitmap = bitmap_lookup[hash]; diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index 85f46b119..d9669a2d7 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -1176,8 +1176,6 @@ namespace wi::gui wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd); } - wi::Color color = GetColor(); - ApplyScissor(canvas, scissorRect, cmd); sprites[IDLE].Draw(cmd); @@ -1691,11 +1689,8 @@ namespace wi::gui } } - const float knobWidth = sprites_knob[state].params.siz.x; - Hitbox2D pointerHitbox = GetPointerHitbox(); - if (pointerHitbox.intersects(hitBox)) { // hover the slider @@ -4018,7 +4013,7 @@ namespace wi::gui { if (onColorChanged == nullptr) return; - EventArgs args; + EventArgs args = {}; args.color = GetPickColor(); onColorChanged(args); } @@ -4411,7 +4406,7 @@ namespace wi::gui item.selected = false; } - EventArgs args; + EventArgs args = {}; args.iValue = -1; onSelect(args); } diff --git a/WickedEngine/wiGUI.h b/WickedEngine/wiGUI.h index be11aa796..0326f46bd 100644 --- a/WickedEngine/wiGUI.h +++ b/WickedEngine/wiGUI.h @@ -17,16 +17,16 @@ namespace wi::gui struct EventArgs { - XMFLOAT2 clickPos; - XMFLOAT2 startPos; - XMFLOAT2 deltaPos; - XMFLOAT2 endPos; - float fValue; - bool bValue; - int iValue; - wi::Color color; - std::string sValue; - uint64_t userdata; + XMFLOAT2 clickPos = {0,0}; + XMFLOAT2 startPos = {0,0}; + XMFLOAT2 deltaPos = {0,0}; + XMFLOAT2 endPos = {0,0}; + float fValue = 0; + bool bValue = false; + int iValue = 0; + wi::Color color = wi::Color::Black(); + std::string sValue = ""; + uint64_t userdata = 0; }; enum WIDGETSTATE diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index 333342f20..b35defc75 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -5352,8 +5352,6 @@ using namespace vulkan_internal; if (validAttachmentCount > 0) { - const TextureDesc& texdesc = renderpass->desc.attachments[0].texture->desc; - internal_state->beginInfo.clearValueCount = validAttachmentCount; internal_state->beginInfo.pClearValues = internal_state->clearColors; @@ -7622,7 +7620,6 @@ using namespace vulkan_internal; void GraphicsDevice_Vulkan::PushConstants(const void* data, uint32_t size, CommandList cmd, uint32_t offset) { CommandList_Vulkan& commandlist = GetCommandList(cmd); - auto& binder = commandlist.binder; if (commandlist.active_pso != nullptr) { diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 9322bff71..a80a81855 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -126,8 +126,6 @@ namespace wi::image image.border_soften = params.border_soften; - size_t vertex_size = sizeof(float4); - STRIP_MODE strip_mode = STRIP_ON; uint32_t index_count = 0; diff --git a/WickedEngine/wiInput.cpp b/WickedEngine/wiInput.cpp index 80e003cdf..a36cfacc9 100644 --- a/WickedEngine/wiInput.cpp +++ b/WickedEngine/wiInput.cpp @@ -417,9 +417,6 @@ namespace wi::input else if (playerindex == 0) // keyboard or mouse { uint8_t keycode = (uint8_t)button; -#ifdef SDL2 - bool keycode_converted = false; -#endif switch (button) { diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp index 1bc2d0d94..1800afa1c 100644 --- a/WickedEngine/wiLua.cpp +++ b/WickedEngine/wiLua.cpp @@ -85,7 +85,6 @@ namespace wi::lua if (argc > 0) { - bool fixedpath = false; uint32_t PID = 0; std::string filename = SGetString(L, 1); diff --git a/WickedEngine/wiMath.cpp b/WickedEngine/wiMath.cpp index daf719a6f..f3b1cae1c 100644 --- a/WickedEngine/wiMath.cpp +++ b/WickedEngine/wiMath.cpp @@ -32,7 +32,6 @@ namespace wi::math ) { float x, y, z, t; - float r1 = 1.0f, r4 = 1.0f; t = atInterval; x = (2 * t*t*t - 3 * t*t + 1)*startPos.x + (-2 * t*t*t + 3 * t*t)*endPos.x + (t*t*t - 2 * t*t + t)*startTangent.x + (t*t*t - t*t)*endTangent.x; y = (2 * t*t*t - 3 * t*t + 1)*startPos.y + (-2 * t*t*t + 3 * t*t)*endPos.y + (t*t*t - 2 * t*t + 1)*startTangent.y + (t*t*t - t*t)*endTangent.y; diff --git a/WickedEngine/wiOcean.cpp b/WickedEngine/wiOcean.cpp index 117ea027d..82380fb5e 100644 --- a/WickedEngine/wiOcean.cpp +++ b/WickedEngine/wiOcean.cpp @@ -449,8 +449,6 @@ namespace wi { wi::Timer timer; - GraphicsDevice* device = wi::graphics::GetDevice(); - RasterizerState ras_desc; ras_desc.fill_mode = FillMode::SOLID; ras_desc.cull_mode = CullMode::NONE; diff --git a/WickedEngine/wiPhysics_Bullet.cpp b/WickedEngine/wiPhysics_Bullet.cpp index 3a0c5c787..026da634d 100644 --- a/WickedEngine/wiPhysics_Bullet.cpp +++ b/WickedEngine/wiPhysics_Bullet.cpp @@ -679,7 +679,6 @@ namespace wi::physics for (size_t ind = 0; ind < physicscomponent->vertex_positions_simulation.size(); ++ind) { uint32_t physicsInd = physicscomponent->graphicsToPhysicsVertexMapping[ind]; - float weight = physicscomponent->weights[physicsInd]; btSoftBody::Node& node = softbody->m_nodes[physicsInd]; diff --git a/WickedEngine/wiRenderPath3D.cpp b/WickedEngine/wiRenderPath3D.cpp index 50f165a4f..dd4883a54 100644 --- a/WickedEngine/wiRenderPath3D.cpp +++ b/WickedEngine/wiRenderPath3D.cpp @@ -746,8 +746,6 @@ void RenderPath3D::Render() const device->WaitCommandList(cmd, cmd_prepareframe); wi::jobsystem::Execute(ctx, [this, cmd](wi::jobsystem::JobArgs args) { - GraphicsDevice* device = wi::graphics::GetDevice(); - wi::renderer::BindCameraCB( *camera, camera_previous, @@ -1556,8 +1554,6 @@ void RenderPath3D::RenderPostprocessChain(CommandList cmd) const { if (wi::renderer::GetTemporalAAEnabled() && !wi::renderer::GetTemporalAADebugEnabled()) { - GraphicsDevice* device = wi::graphics::GetDevice(); - wi::renderer::Postprocess_TemporalAA( temporalAAResources, *rt_read, diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 0b920572e..a5d0d9380 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -2263,7 +2263,6 @@ inline void CreateDirLightShadowCams(const LightComponent& light, CameraComponen const XMVECTOR to = XMVector3TransformNormal(XMVectorSet(0.0f, -1.0f, 0.0f, 0.0f), lightRotation); const XMVECTOR up = XMVector3TransformNormal(XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), lightRotation); const XMMATRIX lightView = XMMatrixLookToLH(XMVectorZero(), to, up); // important to not move (zero out eye vector) the light view matrix itself because texel snapping must be done on projection matrix! - const float nearPlane = camera.zNearP; const float farPlane = camera.zFarP; const float referenceFarPlane = 800.0f; // cascade splits here were tested with this depth range const float referenceSplitClamp = std::min(1.0f, referenceFarPlane / farPlane); // if far plane is greater than reference, do not increase cascade sizes further @@ -3459,8 +3458,6 @@ void UpdateRenderData( ShaderEntity* entityArray = (ShaderEntity*)allocation_entityarray.data; XMMATRIX* matrixArray = (XMMATRIX*)allocation_matrixarray.data; - const XMMATRIX viewMatrix = vis.camera->GetView(); - uint32_t entityCounter = 0; uint32_t matrixCounter = 0; @@ -4083,7 +4080,6 @@ void UpdateRenderDataAsync( const wi::EmittedParticleSystem& emitter = vis.scene->emitters[emitterIndex]; Entity entity = vis.scene->emitters.GetEntity(emitterIndex); const TransformComponent& transform = *vis.scene->transforms.GetComponent(entity); - const MaterialComponent& material = *vis.scene->materials.GetComponent(entity); const MeshComponent* mesh = vis.scene->meshes.GetComponent(emitter.meshID); const uint32_t instanceIndex = uint32_t(vis.scene->objects.GetCount() + vis.scene->hairs.GetCount()) + emitterIndex; @@ -4223,7 +4219,6 @@ void OcclusionCulling_Reset(const Visibility& vis, CommandList cmd) return; } - int query_write = vis.scene->queryheap_idx; const GPUQueryHeap& queryHeap = vis.scene->queryHeap; device->QueryReset( @@ -4462,7 +4457,6 @@ void DrawLightVisualizers( BindCommonResources(cmd); XMMATRIX camrot = XMLoadFloat3x3(&vis.camera->rotationMatrix); - XMMATRIX VP = vis.camera->GetViewProjection(); for (int type = LightComponent::POINT; type < LightComponent::LIGHTTYPE_COUNT; ++type) { @@ -4770,8 +4764,6 @@ void DrawShadowmaps( const ObjectComponent& object = vis.scene->objects[i]; if (object.IsRenderable() && object.IsCastingShadow() && (cascade < (CASCADE_COUNT - object.cascadeMask))) { - Entity cullable_entity = vis.scene->aabb_objects.GetEntity(i); - renderQueue.add(object.mesh_index, uint32_t(i), 0); if (object.GetRenderTypes() & RENDERTYPE_TRANSPARENT || object.GetRenderTypes() & RENDERTYPE_WATER) @@ -4824,8 +4816,6 @@ void DrawShadowmaps( const ObjectComponent& object = vis.scene->objects[i]; if (object.IsRenderable() && object.IsCastingShadow()) { - Entity cullable_entity = vis.scene->aabb_objects.GetEntity(i); - renderQueue.add(object.mesh_index, uint32_t(i), 0); if (object.GetRenderTypes() & RENDERTYPE_TRANSPARENT || object.GetRenderTypes() & RENDERTYPE_WATER) @@ -4884,8 +4874,6 @@ void DrawShadowmaps( const ObjectComponent& object = vis.scene->objects[i]; if (object.IsRenderable() && object.IsCastingShadow()) { - Entity cullable_entity = vis.scene->aabb_objects.GetEntity(i); - renderQueue.add(object.mesh_index, uint32_t(i), 0); if (object.GetRenderTypes() & RENDERTYPE_TRANSPARENT || object.GetRenderTypes() & RENDERTYPE_WATER) @@ -5980,7 +5968,6 @@ void DrawDebugWorld( continue; } const ObjectComponent& object = *scene.objects.GetComponent(x.objectEntity); - const TransformComponent& transform = *scene.transforms.GetComponent(x.objectEntity); if (scene.meshes.GetCount() < object.mesh_index) { continue; @@ -5991,7 +5978,6 @@ void DrawDebugWorld( { continue; } - const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID); GraphicsDevice::GPUAllocation mem = device->AllocateGPU(sizeof(ShaderMeshInstancePointer), cmd); ShaderMeshInstancePointer poi; @@ -6113,7 +6099,6 @@ void DrawDebugWorld( for (size_t i = 0; i < scene.cameras.GetCount(); ++i) { const CameraComponent& cam = scene.cameras[i]; - Entity entity = scene.cameras.GetEntity(i); const float aspect = cam.width / cam.height; XMStoreFloat4x4(&sb.g_xTransform, XMMatrixScaling(aspect * 0.5f, 0.5f, 0.5f) * cam.GetInvView()*camera.GetViewProjection()); @@ -6661,7 +6646,6 @@ void RefreshImpostors(const Scene& scene, CommandList cmd) { continue; } - const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID); ObjectPushConstants push; push.geometryIndex = mesh.geometryOffset + subsetIndex; diff --git a/WickedEngine/wiSDLInput.cpp b/WickedEngine/wiSDLInput.cpp index 9e5c9fafb..5a93caef0 100644 --- a/WickedEngine/wiSDLInput.cpp +++ b/WickedEngine/wiSDLInput.cpp @@ -303,6 +303,7 @@ namespace wi::input::sdlinput case SDL_CONTROLLER_BUTTON_RIGHTSTICK: btnenum = wi::input::GAMEPAD_BUTTON_8; break; case SDL_CONTROLLER_BUTTON_BACK: btnenum = wi::input::GAMEPAD_BUTTON_9; break; case SDL_CONTROLLER_BUTTON_START: btnenum = wi::input::GAMEPAD_BUTTON_10; break; + default: assert(0); return; } btnenum = 1 << (btnenum - wi::input::GAMEPAD_RANGE_START - 1); if(pressed){ diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index c78ecfcf8..8604c9acc 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -3248,7 +3248,7 @@ namespace wi::scene } TransformComponent& transform = transforms[transform_index]; - XMVECTOR rotation_local = XMLoadFloat4(&transform.rotation_local); + //XMVECTOR rotation_local = XMLoadFloat4(&transform.rotation_local); XMVECTOR rotation_parent_world = XMQuaternionIdentity(); XMMATRIX parentWorldMatrix = XMMatrixIdentity(); @@ -3598,7 +3598,6 @@ namespace wi::scene Entity entity = meshes.GetEntity(args.jobIndex); MeshComponent& mesh = meshes[args.jobIndex]; - GraphicsDevice* device = wi::graphics::GetDevice(); if (!mesh.streamoutBuffer.IsValid()) {