2026-02-17 1:34 AM
I am experiencing a segmentation fault when clicking a toggle button inside a ScrollList container.
I have a ScrollList (alarmsSelector) populated with a custom container type called alarmsItem. Each alarmsItem contains a toggle button. When clicked, the button should invoke a callback defined in the parent view (alarmSettingsView).
The callback is initialized in the view constructor as a member variable:
alarmSettingsView::alarmSettingsView():
settingsChanged(false),
saveAlarmsChangesOption(SAVE_ALARMS_CHANGES),
alarmsItemAlarmSelectedCallback(this, &alarmSettingsView::alarmsItemAlarmSelectedCallbackHandler)
{
}In the view
// alarmSettingsView.hpp
protected:
touchgfx::Callback<alarmSettingsView, const int8_t> alarmsItemAlarmSelectedCallback;
void alarmsItemAlarmSelectedCallbackHandler(const int8_t itemIndex);The callback is assigned to each visible item inside ScrollUpdateItem:
void alarmSettingsView::alarmsSelectorScrollUpdateItem(alarmsItem& item, int16_t itemIndex)
{
item.setAlarmSelectedCallback(alarmsItemAlarmSelectedCallback);
}Container (alarmsItem) – callback storage
// alarmsItem.hpp
void setAlarmSelectedCallback(touchgfx::GenericCallback<const int8_t>& callback)
{
alarmSelectedCallback = &callback;
}
protected:
touchgfx::GenericCallback<const int8_t>* alarmSelectedCallback;When the toggle button is clicked, I fire the callback
void alarmsItem::buttonClicked()
{
if (alarmSelectedCallback && alarmSelectedCallback->isValid())
{
alarmSelectedCallback->execute(settingsAlarmsItemIndex);
}
}As soon as the toggle button inside the list is pressed, a segmentation fault occurs at
if (alarmSelectedCallback && alarmSelectedCallback->isValid())What I'm seeing is that alarmSelectedCallback contains the wrong memory address.
I have the same logic in other scroll lists in the code, and they all work correctly, so I'm wondering why this time is triggering a segmentation fault
PS, the container of what the list is made of has the correct trigger attached
Solved! Go to Solution.
2026-02-17 1:49 AM
Just found the issue. The array that populated the scroll list had the wrong dimensions. You can actually delete the question as it is not relevant. The callback is working correctly.
2026-02-17 1:49 AM
Just found the issue. The array that populated the scroll list had the wrong dimensions. You can actually delete the question as it is not relevant. The callback is working correctly.