Fix: Crash when replacing synced AMS filaments #607

Open
opened 2026-04-05 16:23:53 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @tome9111991 on 2/24/2026

Issue

When syncing filaments from an AMS using the "Filament & Color" mode, the application would crash when opened the filament dropdown and attempted to replace a synchronized "Generic PLA" preset with a custom user filament.

Note: The filament colors were displaying correctly after the sync; the crash only occurred at the moment tried to select a different filament from the combobox.

Root Cause

  1. Array Out-Of-Bounds (Crash): In PresetBundle::update_filament_multi_color, iterating over the ams_multi_color_filment list could encounter an empty placeholder (representing an empty or unknown AMS slot). When encountering an empty slot, the loop executed a break instead of a continue. This prematurely terminated the loop, causing the resulting multi-color array to be shorter than the actual number of configured extruders. When tried to change the filament, PresetComboBox::update_ams_color accessed this truncated array out-of-bounds, leading to a fatal crash in std::string::operator=.
  2. Missing Parallel Array Resizing: In PresetBundle::set_num_filaments(unsigned int n, std::vector<std::string> new_colors), only the filament_colour and ams_multi_color_filment arrays were being resized. The arrays filament_colour_type, filament_multi_colour, and filament_map were missing a proper resize, resulting in internal data structures falling out of sync under certain conditions.

Fix

  • Corrected loop behavior in update_filament_multi_color: Changed the premature break to a continue, properly pushing the single filament_colour (or a default #CECECE gray fallback) into the multi-color array when no explicit multi-color information is present. This ensures the array length accurately matches the total extruder count and fixes the out-of-bounds crash when selecting a filament.
  • Synchronized Array Resizing: Added explicit resize() and default initializations for filament_multi_color, filament_colour_type, and filament_map in PresetBundle::set_num_filaments(...) to mirror the safe resize logic already present in the single-string variant of the function.

Should Fix https://github.com/OrcaSlicer/OrcaSlicer/issues/12293

Before PR:

https://github.com/user-attachments/assets/9b6e7e82-cde8-4972-9f8c-ac282c5d1de6

After PR:

https://github.com/user-attachments/assets/8a3103ec-30c7-4d25-8c00-ee05a020c460

*Originally created by @tome9111991 on 2/24/2026* ## Issue When syncing filaments from an AMS using the "Filament & Color" mode, the application would crash when opened the filament dropdown and attempted to replace a synchronized "Generic PLA" preset with a custom user filament. *Note: The filament colors were displaying correctly after the sync; the crash only occurred at the moment tried to select a different filament from the combobox.* ## Root Cause 1. **Array Out-Of-Bounds (Crash):** In `PresetBundle::update_filament_multi_color`, iterating over the `ams_multi_color_filment` list could encounter an empty placeholder (representing an empty or unknown AMS slot). When encountering an empty slot, the loop executed a `break` instead of a `continue`. This prematurely terminated the loop, causing the resulting multi-color array to be shorter than the actual number of configured extruders. When tried to change the filament, `PresetComboBox::update_ams_color` accessed this truncated array out-of-bounds, leading to a fatal crash in `std::string::operator=`. 2. **Missing Parallel Array Resizing:** In `PresetBundle::set_num_filaments(unsigned int n, std::vector<std::string> new_colors)`, only the `filament_colour` and `ams_multi_color_filment` arrays were being resized. The arrays `filament_colour_type`, `filament_multi_colour`, and `filament_map` were missing a proper resize, resulting in internal data structures falling out of sync under certain conditions. ## Fix * **Corrected loop behavior in `update_filament_multi_color`:** Changed the premature `break` to a `continue`, properly pushing the single `filament_colour` (or a default `#CECECE` gray fallback) into the multi-color array when no explicit multi-color information is present. This ensures the array length accurately matches the total extruder count and fixes the out-of-bounds crash when selecting a filament. * **Synchronized Array Resizing:** Added explicit `resize()` and default initializations for `filament_multi_color`, `filament_colour_type`, and `filament_map` in `PresetBundle::set_num_filaments(...)` to mirror the safe resize logic already present in the single-string variant of the function. Should Fix https://github.com/OrcaSlicer/OrcaSlicer/issues/12293 Before PR: https://github.com/user-attachments/assets/9b6e7e82-cde8-4972-9f8c-ac282c5d1de6 After PR: https://github.com/user-attachments/assets/8a3103ec-30c7-4d25-8c00-ee05a020c460
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/OrcaSlicer#607