Skip to content

Commit 0aed849

Browse files
committed
Fixed crashes when opening from LiveSplit
- NotImplementedError from the CaptureInterface - and OutOfRange errors from CaptureMethodDict
1 parent 7410a9f commit 0aed849

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

scripts/install.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Installing Python dependencies
22
$dev = If ($env:GITHUB_JOB -eq 'Build') { '' } Else { '-dev' }
33
pip install wheel --upgrade
4-
pip install -r "$PSScriptRoot/requirements$dev-win32.txt"
4+
pip install -r "$PSScriptRoot/requirements$dev.txt"
55

66
# Don't compile resources on the Build CI job as it'll do so in build script
77
If ($dev) {

src/capture_method/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __eq__(self, other: object):
6666
def __hash__(self):
6767
return self.value.__hash__()
6868

69+
NONE = ""
6970
BITBLT = "BITBLT"
7071
WINDOWS_GRAPHICS_CAPTURE = "WINDOWS_GRAPHICS_CAPTURE"
7172
PRINTWINDOW_RENDERFULLCONTENT = "PRINTWINDOW_RENDERFULLCONTENT"
@@ -74,11 +75,35 @@ def __hash__(self):
7475

7576

7677
class CaptureMethodDict(OrderedDict[CaptureMethodEnum, CaptureMethodInfo]):
78+
7779
def get_method_by_index(self, index: int):
80+
if len(self) <= 0:
81+
return CaptureMethodEnum.NONE
7882
if index < 0:
7983
return next(iter(self))
8084
return list(self.keys())[index]
8185

86+
def __getitem__(self, key: CaptureMethodEnum):
87+
if key == CaptureMethodEnum.NONE:
88+
return NONE_CAPTURE_METHOD
89+
try:
90+
return super().__getitem__(key)
91+
# If requested method does not exists...
92+
except KeyError:
93+
try:
94+
# ...fallback to the first one
95+
return super().__getitem__(self.get_method_by_index(0))
96+
except KeyError:
97+
# ...fallback to an empty capture method to avoid crashes
98+
return NONE_CAPTURE_METHOD
99+
100+
101+
NONE_CAPTURE_METHOD = CaptureMethodInfo(
102+
name="None",
103+
short_description="",
104+
description="",
105+
implementation=CaptureMethodInterface
106+
)
82107

83108
CAPTURE_METHODS = CaptureMethodDict({
84109
CaptureMethodEnum.BITBLT: CaptureMethodInfo(

src/capture_method/interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def get_frame(self, autosplit: AutoSplit) -> tuple[Optional[cv2.Mat], bool]:
2828
2929
@return: The image of the region in the window in BGRA format
3030
"""
31-
raise NotImplementedError()
31+
return None, False
3232

3333
def recover_window(self, captured_window_title: str, autosplit: AutoSplit) -> bool:
34-
raise NotImplementedError()
34+
return False
3535

3636
def check_selected_region_exists(self, autosplit: AutoSplit) -> bool:
3737
return is_valid_hwnd(autosplit.hwnd)

src/menu_bar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def __init__(self, autosplit: AutoSplit):
194194
# Assuming all options take 2 lines (except camera and BitBlt which have 1).
195195
# And all lines take 16 pixels
196196
# And all separators take 2 pixels
197-
doubled_len = 2 * len(capture_method_values)
197+
doubled_len = 2 * len(capture_method_values) or 2
198198
list_view.setMinimumHeight((doubled_len - 2) * 16 + doubled_len)
199199
list_view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
200200
self.capture_method_combobox.setView(list_view)

src/user_profile.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,16 @@ def load_settings_on_open(autosplit: AutoSplit):
163163
if file.endswith(".toml")]
164164

165165
# Find all .tomls in AutoSplit folder, error if there is not exactly 1
166+
error = None
166167
if len(settings_files) < 1:
167-
error_messages.no_settings_file_on_open()
168-
return
169-
if len(settings_files) > 1:
170-
error_messages.too_many_settings_files_on_open()
168+
error = error_messages.no_settings_file_on_open
169+
elif len(settings_files) > 1:
170+
error = error_messages.too_many_settings_files_on_open
171+
if error:
172+
change_capture_method(CAPTURE_METHODS.get_method_by_index(0), autosplit)
173+
error()
171174
return
175+
172176
load_settings(autosplit, os.path.join(auto_split_directory, settings_files[0]))
173177

174178

0 commit comments

Comments
 (0)