Skip to content

Commit cf9aef0

Browse files
committed
put _wrap_port_ptr calls in try statment, to avoid errors when port is nor audio nor midi
1 parent 1db027c commit cf9aef0

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/jack.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,10 @@ def set_port_registration_callback(self, callback=None,
10481048
def callback_wrapper(port_id, register, _):
10491049
port_ptr = _lib.jack_port_by_id(self._ptr, port_id)
10501050
if port_ptr:
1051-
port = self._wrap_port_ptr(port_ptr)
1051+
try:
1052+
port = self._wrap_port_ptr(port_ptr)
1053+
except AssertionError:
1054+
return
10521055
elif only_available:
10531056
return
10541057
else:
@@ -1121,7 +1124,10 @@ def callback_wrapper(a, b, connect, _):
11211124
for idx in 0, 1:
11221125
ptr = _lib.jack_port_by_id(self._ptr, port_ids[idx])
11231126
if ptr:
1124-
ports[idx] = self._wrap_port_ptr(ptr)
1127+
try:
1128+
ports[idx] = self._wrap_port_ptr(ptr)
1129+
except AssertionError:
1130+
return
11251131
elif only_available:
11261132
return
11271133
else:
@@ -1184,7 +1190,10 @@ def set_port_rename_callback(self, callback=None, only_available=True):
11841190
def callback_wrapper(port_id, old_name, new_name, _):
11851191
port_ptr = _lib.jack_port_by_id(self._ptr, port_id)
11861192
if port_ptr:
1187-
port = self._wrap_port_ptr(port_ptr)
1193+
try:
1194+
port = self._wrap_port_ptr(port_ptr)
1195+
except AssertionError:
1196+
return
11881197
elif only_available:
11891198
return
11901199
else:
@@ -1534,7 +1543,13 @@ def get_port_by_name(self, name):
15341543
port_ptr = _lib.jack_port_by_name(self._ptr, name.encode())
15351544
if not port_ptr:
15361545
raise JackError(f'Port {name!r} not available')
1537-
return self._wrap_port_ptr(port_ptr)
1546+
1547+
try:
1548+
port = self._wrap_port_ptr(port_ptr)
1549+
except AssertionError:
1550+
raise JackError(f'Port {name!r} not audio or midi')
1551+
1552+
return port
15381553

15391554
def get_all_connections(self, port):
15401555
"""Return a list of ports which the given port is connected to.
@@ -1762,7 +1777,13 @@ def _register_port(self, name, porttype, is_terminal, is_physical, flags):
17621777
if not port_ptr:
17631778
raise JackError(
17641779
f'{name!r}: port registration failed')
1765-
return self._wrap_port_ptr(port_ptr)
1780+
1781+
try:
1782+
port = self._wrap_port_ptr(port_ptr)
1783+
except AssertionError:
1784+
raise JackError(
1785+
f'{name!r}: port registration failed, not audio or midi')
1786+
return port
17661787

17671788
def _port_list_from_pointers(self, names):
17681789
"""Get list of Port objects from char**."""

0 commit comments

Comments
 (0)