Skip to main content
Senior III
February 17, 2026
Solved

TouchGFX ScrollList – Segmentation Fault on Button Callback

  • February 17, 2026
  • 1 reply
  • 357 views

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

nico23_0-1771320792211.png

 

Best answer by nico23

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.

1 reply

nico23AuthorBest answer
Senior III
February 17, 2026

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.