sdrangel icon indicating copy to clipboard operation
sdrangel copied to clipboard

ChannelAPI::getIndexInDeviceSet() not valid in channelAdded slot

Open srcejon opened this issue 10 months ago • 3 comments

In a MainCore::channelAdded(int deviceSetIndex, ChannelAPI *channel) slot, it appears channel->getIndexInDeviceSet() is not valid.

This seems to come from the ordering of the following code:

void DeviceSet::addChannelInstance(ChannelAPI *channelAPI)
   ...
    mainCore->addChannelInstance(this, channelAPI);
    renameChannelInstances();

addChannelInstance emits the channelAdded signal, but the index isn't set until afterwards in renameChannelInstances().

srcejon avatar Apr 08 '24 14:04 srcejon

Inverting the two lines may just work:

void DeviceSet::addChannelInstance(ChannelAPI *channelAPI)
{
    MainCore *mainCore = MainCore::instance();
    m_channelInstanceRegistrations.append(channelAPI);
    renameChannelInstances();
    mainCore->addChannelInstance(this, channelAPI);
}

The "append" adds the channel at the end if the m_channelInstanceRegistrations list then renameChannelInstances() will just loop through this list and set the channel index in device set to the current index. This sets the index in the channelAPI to the last index which makes sense. Before renameChannelInstances() is invoked this index may not be set correctly.

In seems to me a similar situation exists in other parts of the code:

  • addMIMOchannel
  • addRxChennel
  • addTxChannel

One may also take a look at the channel removal methods although I suppose that what we want here is the index of the channel that has been deleted which in this case is correct.

f4exb avatar Apr 09 '24 21:04 f4exb

Swapping the order seemed to work, for what I was looking at, but renameChannelInstances can emit an indexInDeviceSetChanged signal - and I don't know if there's any code that might be dependent on the ordering of those two signals. Couldn't see anything from a quick search. .

srcejon avatar Apr 09 '24 22:04 srcejon

This issue is going to be closed due to inactivity

github-actions[bot] avatar May 20 '24 04:05 github-actions[bot]