17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-09 00:17:39 +01:00

fix: the bugs and vulnerabilities SonarCloud reports on PR #216

This commit is contained in:
2026-11-07 22:11:08 +01:00
parent 8e85def98f
commit 7667e5b2ec
65 changed files with 910 additions and 121 deletions

View File

@@ -108,7 +108,14 @@ namespace vk14
cab_probe_maps::~cab_probe_maps()
{
destroy();
try
{
destroy();
}
catch (std::exception const &)
{
// out of memory while letting the maps go: what's left is released with the device, which beats terminating
}
}
void cab_probe_maps::init(VkDevice const Device, allocator &Memory, deletion_queue &Deletions)
@@ -351,7 +358,8 @@ void vulkan14_renderer::render_cab_probe()
// the lights of the cab light the probe when they're lights of the frame
std::vector<gfx::local_lights::cab_light> const nolights;
auto const &lights{(vehicle != nullptr) && (m_locallights.cab_lamp_vehicle() == vehicle) ? m_locallights.cab_lights() : nolights};
if (false == probe.update_wanted(vehicle, (vehicle != nullptr ? vehicle->mdKabina : nullptr), center, extent, lights, m_framestamp))
// update_wanted() wants no update without a vehicle, but is called anyway to forget the probe
if ((false == probe.update_wanted(vehicle, (vehicle != nullptr ? vehicle->mdKabina : nullptr), center, extent, lights, m_framestamp)) || (vehicle == nullptr))
{
return;
}

View File

@@ -255,6 +255,11 @@ void compute_queue_scope(VkPipelineStageFlags2 &Stage, VkAccessFlags2 &Access)
template <typename Barrier_> void compute_queue_barriers(Barrier_ *Barriers, std::uint32_t const Count)
{
// none of the kind: the stream holds no data for them
if (Barriers == nullptr)
{
return;
}
for (std::uint32_t i = 0; i < Count; ++i)
{
compute_queue_scope(Barriers[i].srcStageMask, Barriers[i].srcAccessMask);

View File

@@ -11,8 +11,6 @@ http://mozilla.org/MPL/2.0/.
#include "rendering/vulkan14/vulkan14grass.h"
#include "utilities/Logs.h"
#include <cstring>
namespace vk14
{
@@ -132,7 +130,7 @@ grass_field::chunk_images const *grass_field::images(chunk_draw const &Draw)
}
table[4 * 4 + 0] = Draw.share;
table[4 * 4 + 1] = Draw.chunk;
if ((false == chunk.table_made) || (std::memcmp(table.data(), chunk.table.data(), sizeof(table)) != 0) || (chunk.images[3] == nullptr))
if ((false == chunk.table_made) || (table != chunk.table) || (chunk.images[3] == nullptr))
{
auto map{chunk.images[3]};
if (map == nullptr)

View File

@@ -665,7 +665,8 @@ void vulkan14_renderer::render_instances_indirect()
// the draws, recorded while the gpu culls
record_indirect_draws(cull, false);
auto const twophase{cull.two_phase()};
// two phases only with the occlusion test, which needs the targets
auto const twophase{useocclusion && cull.two_phase()};
auto const draws{false == m_indirectdraws.empty()};
// the depth comes first in the depth pass of the whole scene, which leaves the colour to the colour pass, and with the depth
// prepass of the instances

View File

@@ -111,7 +111,8 @@ void vulkan14_renderer::render_local_shadows()
// only the light buffers with the lamps read the maps
auto const *vehicle{Global.gfx_lights_clustered ? m_locallights.cab_lamp_vehicle() : nullptr};
lamps.update_cab(vehicle, (vehicle != nullptr ? vehicle->mdKabina : nullptr), m_locallights.cab_lights(), m_framestamp);
if (lamps.cab_draws().empty())
// without a vehicle there are no draws either
if ((vehicle == nullptr) || lamps.cab_draws().empty())
{
return;
}

View File

@@ -53,20 +53,29 @@ void add(std::uint64_t const Handle, entry &&Entry)
g_live[Handle] = std::move(Entry);
}
void remove(std::uint64_t const Handle)
// called by the destructors of buffers and images, so it lets no exception out: the registry only serves the report after
// a device loss, and a resource it fails to move to the freed ones mustn't stop the resource from being released
void remove(std::uint64_t const Handle) noexcept
{
std::lock_guard<std::mutex> lock(g_mutex);
auto const lookup{g_live.find(Handle)};
if (lookup == g_live.end())
try
{
return;
std::scoped_lock lock(g_mutex);
auto const lookup{g_live.find(Handle)};
if (lookup == g_live.end())
{
return;
}
lookup->second.freed = std::chrono::steady_clock::now();
g_freed.push_back(std::move(lookup->second));
g_live.erase(lookup);
if (g_freed.size() > freed_kept)
{
g_freed.pop_front();
}
}
lookup->second.freed = std::chrono::steady_clock::now();
g_freed.push_back(std::move(lookup->second));
g_live.erase(lookup);
if (g_freed.size() > freed_kept)
catch (std::exception const &)
{
g_freed.pop_front();
// the entry stays among the live ones, which the report can live with
}
}

View File

@@ -340,7 +340,14 @@ std::string shader_library::info() const
pipeline_library::~pipeline_library()
{
shutdown();
try
{
shutdown();
}
catch (std::exception const &)
{
// writing the pipeline cache failed on the way out: the cache is only rebuilt next time, which beats terminating
}
}
bool pipeline_library::init(device const &Device, std::string &Reason)