mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-05 15:42:31 +01:00
fix(sonar): addressing reliability/security issues
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <mutex>
|
||||
|
||||
#include "model/Texture.h"
|
||||
#include "rendering/renderer.h"
|
||||
@@ -14,26 +13,16 @@ public:
|
||||
deferred_image() = default;
|
||||
deferred_image(const std::string &p) : path(p) { }
|
||||
deferred_image(const deferred_image&) = delete;
|
||||
deferred_image(deferred_image &&other) noexcept : deferred_image(std::move(other), std::scoped_lock(other.mutex)) { }
|
||||
~deferred_image() = default;
|
||||
deferred_image &operator=(deferred_image &&other) noexcept
|
||||
{
|
||||
if (this != &other) {
|
||||
std::scoped_lock lock(mutex, other.mutex);
|
||||
path = std::move(other.path);
|
||||
image = other.image;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
deferred_image(deferred_image&&) = default;
|
||||
deferred_image &operator=(deferred_image&&) = default;
|
||||
operator bool() const
|
||||
{
|
||||
std::scoped_lock lock(mutex);
|
||||
return image != null_handle || !path.empty();
|
||||
}
|
||||
|
||||
GLuint get() const
|
||||
// loads the texture on first use
|
||||
GLuint get()
|
||||
{
|
||||
std::scoped_lock lock(mutex);
|
||||
if (!path.empty()) {
|
||||
image = GfxRenderer->Fetch_Texture(path, true);
|
||||
path.clear();
|
||||
@@ -52,7 +41,6 @@ public:
|
||||
|
||||
glm::ivec2 size() const
|
||||
{
|
||||
std::scoped_lock lock(mutex);
|
||||
if (image != null_handle) {
|
||||
auto &tex = GfxRenderer->Texture(image);
|
||||
return glm::ivec2(tex.get_width(), tex.get_height());
|
||||
@@ -61,11 +49,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
// moves content of the other image, while the caller holds its lock
|
||||
deferred_image(deferred_image &&other, std::scoped_lock<std::mutex> const &) noexcept : path(std::move(other.path)), image(other.image) { }
|
||||
|
||||
// guards lazy loading performed by the const accessors
|
||||
mutable std::mutex mutex;
|
||||
mutable std::string path;
|
||||
mutable texture_handle image = 0;
|
||||
std::string path;
|
||||
texture_handle image = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user