monitor texture and shader file writes using inotify: improved resource management v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 10 Dec 2023 22:20:37 +0100
branchv_0
changeset 23 42341f66de52
parent 22 12262f2420de
child 24 98d033d3ef7c
monitor texture and shader file writes using inotify: improved resource management
FileMonitor.cpp
--- a/FileMonitor.cpp	Wed Dec 06 22:55:43 2023 +0100
+++ b/FileMonitor.cpp	Sun Dec 10 22:20:37 2023 +0100
@@ -52,9 +52,9 @@
 	std::map<int, std::string> fileNames;
 
 	void unwatch(int wd) {
+		fileNames.erase(wd);
 		int result = inotify_rm_watch(fd, wd);
 		checkError(result < 0, "unable to stop monitoring a file: ");
-		fileNames.erase(wd);
 	}
 
 	virtual ~Impl() {
@@ -109,7 +109,12 @@
 }
 
 WatchedFile::Impl::~Impl() {
-	fileMonitorImpl->unwatch(wd);
+	try {
+		fileMonitorImpl->unwatch(wd);
+	} catch (const std::exception& e) {
+		// ignored, fails after file deletion
+		// std::cerr << "unwatch failed: " << e.what() << std::endl;
+	}
 }
 
 FileMonitor WatchedFile::getFileMonitor() const {