aboutsummaryrefslogtreecommitdiff
path: root/src/SfmlFixes.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-21 21:32:51 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-21 22:31:36 +0200
commit0d8293a5647c2bb10228658f0910515b38ff0d64 (patch)
treee97c10442c73e330672277940aaf0b38d2fc63eb /src/SfmlFixes.cpp
parent87fb6e5c0cce6e6aba8f646329af6f8070d27c63 (diff)
Workaround sfml image loading thread race condition
See: https://github.com/SFML/SFML/issues/1711 Also some other smaller changes
Diffstat (limited to 'src/SfmlFixes.cpp')
-rw-r--r--src/SfmlFixes.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/SfmlFixes.cpp b/src/SfmlFixes.cpp
new file mode 100644
index 0000000..d6d4b17
--- /dev/null
+++ b/src/SfmlFixes.cpp
@@ -0,0 +1,15 @@
+#include "../include/SfmlFixes.hpp"
+#include <mutex>
+
+static std::mutex mutex;
+namespace QuickMedia {
+ bool load_image_from_file(sf::Image &image, const std::string &filepath) {
+ std::lock_guard<std::mutex> lock(mutex);
+ return image.loadFromFile(filepath);
+ }
+
+ bool load_image_from_memory(sf::Image &image, const void *data, size_t size) {
+ std::lock_guard<std::mutex> lock(mutex);
+ return image.loadFromMemory(data, size);
+ }
+} \ No newline at end of file