From cf9aef0f2212555b13871305cc69f27bb59cc6a3 Mon Sep 17 00:00:00 2001 From: Houston4444 Date: Mon, 3 Nov 2025 21:49:29 +0100 Subject: [PATCH] put _wrap_port_ptr calls in try statment, to avoid errors when port is nor audio nor midi --- src/jack.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/jack.py b/src/jack.py index 52e86b4..0219be3 100644 --- a/src/jack.py +++ b/src/jack.py @@ -1048,7 +1048,10 @@ def set_port_registration_callback(self, callback=None, def callback_wrapper(port_id, register, _): port_ptr = _lib.jack_port_by_id(self._ptr, port_id) if port_ptr: - port = self._wrap_port_ptr(port_ptr) + try: + port = self._wrap_port_ptr(port_ptr) + except AssertionError: + return elif only_available: return else: @@ -1121,7 +1124,10 @@ def callback_wrapper(a, b, connect, _): for idx in 0, 1: ptr = _lib.jack_port_by_id(self._ptr, port_ids[idx]) if ptr: - ports[idx] = self._wrap_port_ptr(ptr) + try: + ports[idx] = self._wrap_port_ptr(ptr) + except AssertionError: + return elif only_available: return else: @@ -1184,7 +1190,10 @@ def set_port_rename_callback(self, callback=None, only_available=True): def callback_wrapper(port_id, old_name, new_name, _): port_ptr = _lib.jack_port_by_id(self._ptr, port_id) if port_ptr: - port = self._wrap_port_ptr(port_ptr) + try: + port = self._wrap_port_ptr(port_ptr) + except AssertionError: + return elif only_available: return else: @@ -1534,7 +1543,13 @@ def get_port_by_name(self, name): port_ptr = _lib.jack_port_by_name(self._ptr, name.encode()) if not port_ptr: raise JackError(f'Port {name!r} not available') - return self._wrap_port_ptr(port_ptr) + + try: + port = self._wrap_port_ptr(port_ptr) + except AssertionError: + raise JackError(f'Port {name!r} not audio or midi') + + return port def get_all_connections(self, port): """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): if not port_ptr: raise JackError( f'{name!r}: port registration failed') - return self._wrap_port_ptr(port_ptr) + + try: + port = self._wrap_port_ptr(port_ptr) + except AssertionError: + raise JackError( + f'{name!r}: port registration failed, not audio or midi') + return port def _port_list_from_pointers(self, names): """Get list of Port objects from char**."""