fix(channels): pre-allocate reader.channels to prevent lib corruption

meshcore lib 2.2.21 bug: reader.py line 434 does
  self.channels = self.channels.extend([...])
which sets self.channels = None (extend returns None).
This corrupts ALL subsequent channel message processing.

Fix: after getting max_channels from device_info, pre-allocate
mc._reader.channels to max_channels slots so the extend path
is never triggered.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-03-06 10:05:17 +01:00
parent 8821892b4c
commit dc8c7ad1d6
+10
View File
@@ -178,6 +178,16 @@ class DeviceManager:
except Exception as e:
logger.warning(f"Could not fetch device_info: {e}")
# Workaround: meshcore lib 2.2.21 has a bug where list.extend()
# return value (None) corrupts reader.channels for idx >= 20.
# Pre-allocate the channels list to max_channels to avoid this.
reader = getattr(self.mc, '_reader', None)
if reader and hasattr(reader, 'channels'):
current = reader.channels or []
if len(current) < self._max_channels:
reader.channels = current + [{} for _ in range(self._max_channels - len(current))]
logger.debug(f"Pre-allocated reader.channels to {len(reader.channels)} slots")
logger.info(f"Connected to device: {self._device_name} "
f"(key: {self._self_info.get('public_key', '?')[:8]}...)")