--- a/CLIParser.h Sat Jan 06 01:04:15 2024 +0100
+++ b/CLIParser.h Tue Oct 08 22:24:40 2024 +0200
@@ -48,7 +48,7 @@
parseHexColor(const std::string& hex) {
size_t count;
unsigned long rgb = std::stoul(hex, &count, 16);
- if (count == 6 || count == 8 && hex.starts_with("0x")) return rgb;
+ if (count == 6 || (count == 8 && hex.starts_with("0x"))) return rgb;
else throw std::logic_error("Invalid hex color string");
// the input should be (0x)?[0-9a-fA-F]{6}, however:
// values like 0x0123 are also accepted and interpreted as 000123
--- a/Makefile Sat Jan 06 01:04:15 2024 +0100
+++ b/Makefile Tue Oct 08 22:24:40 2024 +0200
@@ -13,6 +13,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+CXX ?= g++
+CXXFLAGS ?= -O2 -g3 -ggdb -Wall -Wno-sign-compare
+CXXFLAGS += --std=c++20
+# CXXFLAGS += -Wextra
+LDFLAGS = $(shell pkg-config --cflags --libs epoxy x11 glu glm Magick++)
+
+ifeq ($(MODE), dev)
+CXXFLAGS += -fsanitize=undefined -fsanitize=address
+endif
+
+# TODO: provide debug symbols in separate files
+
all: build/shader-shark
.PHONY: all clean run
@@ -23,17 +35,9 @@
run: build/shader-shark
SHADER_SHARK_DATA_DIR=. $(<)
-SRC= \
- Shark.cpp \
- shader-shark.cpp \
- ImageLoader.cpp \
- Texture.cpp \
- Shader.cpp \
- Program.cpp \
- XAttrs.cpp \
- FileMonitor.cpp
+SRC = $(shell find -maxdepth 1 -name '*.cpp')
+HEADERS = $(shell find -maxdepth 1 -name '*.h')
-build/shader-shark: $(SRC) *.h
+build/shader-shark: $(SRC) $(HEADERS)
mkdir -p build
- $(CXX) -std=c++20 -g -o $(@) $(SRC) $$(pkg-config --cflags --libs \
- epoxy x11 glu glm Magick++)
+ $(CXX) $(CXXFLAGS) -o $(@) $(SRC) $(LDFLAGS)
--- a/MappedFile.h Sat Jan 06 01:04:15 2024 +0100
+++ b/MappedFile.h Tue Oct 08 22:24:40 2024 +0200
@@ -45,9 +45,11 @@
}
virtual ~MappedFile() {
- int result = munmap(data, size);
+ // int result =
+ munmap(data, size);
// std::cerr << "~MappedFile() / munmap() = " << result << std::endl;
- result = close(fd);
+ // result =
+ close(fd);
// std::cerr << "~MappedFile() / close() = " << result << std::endl;
}
--- a/Shark.cpp Sat Jan 06 01:04:15 2024 +0100
+++ b/Shark.cpp Tue Oct 08 22:24:40 2024 +0200
@@ -641,7 +641,7 @@
// glBindFragDataLocation(program, 0, "outColor");
// glBindAttribLocation(program, LOC.input, "vertices");
- for (const Configuration::Shader definition : cfg.shaders) {
+ for (const Configuration::Shader& definition : cfg.shaders) {
Shader::Type type;
std::string fileName = definition.fileName;
if (definition.type == "fragment") type = Shader::Type::FRAGMENT;
--- a/XAttrs.cpp Sat Jan 06 01:04:15 2024 +0100
+++ b/XAttrs.cpp Tue Oct 08 22:24:40 2024 +0200
@@ -124,16 +124,30 @@
std::string value;
bool exists = true;
bool loaded = false;
+
+private:
+ Impl(const Impl&) = delete;
+ Impl& operator=(const Impl&) = delete;
};
class XAttrs::Impl {
public:
+
+ Impl() {
+ }
+
+ virtual ~Impl() {
+ }
std::string nameSpace;
std::string fileName;
std::vector<Attribute> attributes;
bool loaded = false;
const XAttrs::Attribute& save(const XAttrs::Attribute& attribute);
XAttrs::Attribute& load(XAttrs::Attribute& attribute);
+
+private:
+ Impl(const Impl&) = delete;
+ Impl& operator=(const Impl&) = delete;
};
XAttrs::XAttrs(const std::string& fileName, const std::string& nameSpace) :
@@ -143,6 +157,9 @@
}
XAttrs::~XAttrs() {
+ // Break circular dependency (otherwise we have a memory leak),
+ // this collection is not needed anymore:
+ impl->attributes.clear();
}
const std::string XAttrs::getFileName() const {