Skip to content

Commit f0d7171

Browse files
fix: Window tiling edge cases (#603)
Changes the way locking is handled in the event of a crash or slightly weird timing windows. We now wait for 2 consecutive polls with no changes before proceeding, and only cleans up stale locks based on file data. --------- Co-authored-by: Tamás Gálffy <ezittgtx@gmail.com>
1 parent cac71a5 commit f0d7171

5 files changed

Lines changed: 37 additions & 14 deletions

File tree

addons/netfox.extras/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.extras"
44
description="Game-specific utilities for Netfox"
55
author="Tamas Galffy and contributors"
6-
version="1.43.5"
6+
version="1.43.6"
77
script="netfox-extras.gd"

addons/netfox.extras/window-tiler.gd

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func _ready() -> void:
2828
_logger.debug("Environment variable %s set, disabling", [env_var])
2929
return
3030

31-
# Cleanup in case some files were left
32-
_cleanup()
31+
if not _has_recent_locks(3):
32+
_cleanup()
3333

3434
# Running embedded in editor
3535
if _is_embedded():
@@ -48,15 +48,22 @@ func _ready() -> void:
4848

4949
# Search for locks, stop once no new locks are found
5050
var locks = []
51+
var stable_polls := 0
5152
await get_tree().create_timer(0.25).timeout
53+
54+
# Limit to 20 attempts
5255
for i in range(20):
5356
await get_tree().create_timer(0.1).timeout
5457
var new_locks = _list_lock_ids()
5558

5659
if locks == new_locks:
57-
break
60+
stable_polls += 1
61+
else:
62+
locks = new_locks
63+
stable_polls = 0
5864

59-
locks = new_locks
65+
if stable_polls >= 2:
66+
break
6067

6168
var tile_count = locks.size()
6269
var idx = locks.find(_uid)
@@ -91,17 +98,33 @@ func _list_lock_ids() -> Array[String]:
9198
return result
9299

93100
func _cleanup():
94-
var result: Array[String] = []
95101
var dir := DirAccess.open(OS.get_cache_dir())
96102

97103
if dir:
98104
for f in dir.get_files():
99-
if f.begins_with(_prefix) and _get_sid(f) != _sid:
100-
_logger.trace("Cleaned up lock: %s", [f])
101-
dir.remove(OS.get_cache_dir() + "/" + f)
105+
if not f.begins_with(_prefix):
106+
continue
107+
108+
var lock_path = OS.get_cache_dir() + "/" + f
109+
_logger.trace("Cleaned lock: %s", [f])
110+
dir.remove(lock_path)
102111

103-
func _get_sid(filename: String) -> String:
104-
return filename.substr(_prefix.length() + 1).get_slice("-", 0)
112+
func _has_recent_locks(seconds: int) -> bool:
113+
var dir := DirAccess.open(OS.get_cache_dir())
114+
var now := int(Time.get_unix_time_from_system())
115+
116+
if not dir:
117+
return false
118+
119+
for f in dir.get_files():
120+
if not f.begins_with(_prefix):
121+
continue
122+
123+
var modified := int(FileAccess.get_modified_time(OS.get_cache_dir() + "/" + f))
124+
if modified > 0 and now - modified <= seconds:
125+
return true
126+
127+
return false
105128

106129
func _get_uid(filename: String) -> String:
107130
return filename.substr(_prefix.length() + 1).get_slice("-", 1)

addons/netfox.internals/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.internals"
44
description="Shared internals for netfox addons"
55
author="Tamas Galffy and contributors"
6-
version="1.43.5"
6+
version="1.43.6"
77
script="plugin.gd"

addons/netfox.noray/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.noray"
44
description="Bulletproof your connectivity with noray integration for netfox"
55
author="Tamas Galffy and contributors"
6-
version="1.43.5"
6+
version="1.43.6"
77
script="netfox-noray.gd"

addons/netfox/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox"
44
description="Shared internals for netfox addons"
55
author="Tamas Galffy and contributors"
6-
version="1.43.5"
6+
version="1.43.6"
77
script="netfox.gd"

0 commit comments

Comments
 (0)