Skip to content

deleting a custom color palette (one of 20) changes effects that use another custom palette #5533

Closed

Description

@adam-61

What happened?

I have bout 24 custom palettes and when i delete 1 from the middle like palette number 19/20, other custom color palettes does not change color according to the saved color

To Reproduce Bug

deleting custom palette does not change other custom color palettes

Image Image

Expected Behavior

other custom color palettes should stay the same but does not when deleting 1 of 20

Install Method

Binary from WLED.me

What version of WLED?

0.17

Which microcontroller/board are you seeing the problem on?

ESP32

Relevant log/trace output

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. DedeHai commented on Apr 24, 2026

    @DedeHai
    Collaborator

    you may have hit a weak point in color delete algorithm

  2. adam-61 commented on Apr 24, 2026

    @adam-61
    Author

    What you mean by weak point

  3. adam-61 commented on Apr 24, 2026

    @adam-61
    Author

    well i have to go to palette option and then save each of the custom palettes on top of them, which kind of fixed the issue but is this a common bug like no saving other palettes properly ?

  4. DedeHai commented on Apr 24, 2026

    @DedeHai
    Collaborator

    @coderabbitai is the issue related to custom palettes file scan or is it unrelated?

  5. coderabbitai commented on Apr 24, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/bin/bash
    # Fetch the issue details
    gh issue view 5533 --repo wled/WLED --comments
    

    Length of output: 652


    🏁 Script executed:

    #!/bin/bash
    # Search for custom palettes file scan related code
    rg -n "palette" --type=cpp -l | head -20
    rg -n "customPalette\|custom_palette\|palette.*scan\|scan.*palette\|palette.*file\|file.*palette" --type=cpp -C3 | head -100
    

    Length of output: 801


    🏁 Script executed:

    #!/bin/bash
    # Get issue body/title
    gh issue view 5533 --repo wled/WLED --json title,body,labels,createdAt
    
    # Look at custom palette file scanning code
    cat wled00/palettes.cpp
    
    # Also check set.cpp for palette-related code
    rg -n "palette" wled00/set.cpp -A2 -B2 | head -80
    

    Length of output: 28409


    🏁 Script executed:

    #!/bin/bash
    # Look at the loadCustomPalettes function and any delete palette logic
    rg -n "loadCustomPalettes\|deleteCustomPalette\|customPalette\|custom.*palette\|palette.*delete\|deletePalette" --type=cpp -A5 -B2 | head -200
    
    # Also check filesystem/file scanning for palettes
    rg -n "\.json\|SPIFFS\|LittleFS\|openDir\|scanDir" wled00/set.cpp -A3 -B2 | head -80
    

    Length of output: 0


    🏁 Script executed:

    #!/bin/bash
    # Search more broadly for custom palette loading functions
    rg -n "loadCustomPalette\|customPal\|palettes.*load\|load.*palette" -C3 | head -150
    
    # Check wled.h for palette-related declarations
    rg -n "palette\|Palette" wled00/wled.h | head -60
    
    # Check presets.cpp for palette file handling
    cat wled00/presets.cpp | head -150
    
    # Look at filesystem scan for palette json files
    rg -n "p_[0-9]\|pal\|\.json" wled00/presets.cpp | head -60
    

    Length of output: 4317


    🏁 Script executed:

    #!/bin/bash
    # Find where loadCustomPalettes is defined
    rg -rn "loadCustomPalettes\|customPalettes\|customPal" --type=cpp -C5
    
    # Also check wled_server.cpp for palette delete handling
    rg -n "delete\|Delete\|palette\|Palette" wled00/wled_server.cpp | head -60
    
    # Check what files contain palette file operations  
    rg -rn "p_\d\+\.json\|palette.*json\|json.*palette\|/pal\|pal.*\.json" -C3 | head -100
    

    Length of output: 0


    🏁 Script executed:

    #!/bin/bash
    # Try finding the function with broader search
    grep -rn "loadCustomPalettes\|customPal" wled00/ 2>/dev/null | head -50
    
    # Check the full util.cpp since it was listed in palette-related files
    grep -n "palette\|Palette\|pal" wled00/util.cpp | head -80
    
    # Check xml.cpp for palette scanning/enumeration
    grep -n "palette\|Palette\|pal\|delete\|scan" wled00/xml.cpp | head -80
    

    Length of output: 2674


    🏁 Script executed:

    #!/bin/bash
    # Read the loadCustomPalettes function in colors.cpp
    sed -n '255,350p' wled00/colors.cpp
    
    # Also check the palette delete handling in wled_server.cpp
    sed -n '210,240p' wled00/wled_server.cpp
    
    # Look at FX_fcn.cpp for the custom palette index logic
    sed -n '225,300p' wled00/FX_fcn.cpp
    sed -n '580,600p' wled00/FX_fcn.cpp
    

    Length of output: 9570


    @DedeHai — Yes, this issue is directly related to the custom palettes file scan in loadCustomPalettes() (wled00/colors.cpp, Line 262).

    Here's what happens:

    Root cause: Custom palettes are stored as sequentially-numbered files (/palette0.json, /palette1.json, …, /palette23.json). loadCustomPalettes() scans these files in order and pushes each valid one into the customPalettes[] vector. Custom palette IDs are assigned top-down from 255: customPalettes[0] → palette ID 255, customPalettes[1] → palette ID 254, etc.

    When the user deletes /palette19.json, the file scan compacts the vector:

    After deletion File Vector slot Palette ID
    (unchanged) palette18.json [18] 237
    (shifted!) palette20.json [19] 236 ← was 235
    (shifted!) palette21.json [20] 235 ← was 234
    … … … …

    Every custom palette after the deleted one shifts by one slot in the vector, changing its effective palette ID. Since segments/presets store the numeric palette ID, they now silently reference the wrong palette.

    The workaround the user found (re-saving each palette on top of itself) works because it re-aligns the file numbering with the stored IDs.

    This is the weak point: loadCustomPalettes() compacts the vector over any file gap without updating the palette IDs saved in segment/preset state. A possible fix would be to either:

    1. Preserve gaps in the customPalettes vector (insert a placeholder/null palette for missing files), or
    2. Renumber all subsequent palette files when one is deleted, keeping indices contiguous, or
    3. Update all palette references in presets/segments after a deletion.
  6. DedeHai commented on Apr 24, 2026

    @DedeHai
    Collaborator

    @adamjensen61 actually this is expected behaviour, if you delete a cutom palette, they do get re-assigned numbers, changing all subsequent custom palettes.

  7. adam-61 commented on Apr 25, 2026

    @adam-61
    Author

    yeh they get re-assigned but the colors dnt match with the palettes if i delete 1 from the middle, i guess i have to keep or change to another color

  8. DedeHai commented on Apr 25, 2026

    @DedeHai
    Collaborator

    well i have to go to palette option and then save each of the custom palettes on top of them, which kind of fixed the issue but is this a common bug like no saving other palettes properly ?

    it is not a "common bug" as having more than 3 custom palettes is quite a new feature. it could use improvement for better usability, for example by inserting stubs into the vector as the rabbit sais. not sure its easily feasible without rewriting a whole bunch of palette handling code.

  9. DedeHai commented on Apr 25, 2026

    @DedeHai
    Collaborator

    @adamjensen61 I fixed this by keeping the ID's of custom palettes consistent when deleting palettes. Please check if this fixes your finding, it will be in the nightly release tomorrow.

  10. adam-61 commented on Apr 26, 2026

    @adam-61
    Author

    @DedeHai Yeh it fixed the issue, i saved those palettes again soo few of my playlist is messed up with different colors, thanks for the fix

  11. adam-61 commented on Apr 26, 2026

    @adam-61
    Author

    @DedeHai Btw i think if you like keep it at default color like amber by not deleting the whole palette file, that would be good coz of the missing palette number

    Image
  12. adam-61 commented on Apr 26, 2026

    @adam-61
    Author

    Also you could add option for like naming/renaming custom palettes

  13. DedeHai commented on Apr 26, 2026

    @DedeHai
    Collaborator

    not showing unused custom palettes was intentional to not clutter the list, they are replaced automatically when you save a new one. using names for palettes is a frequent request, however there is currently no code structure to support that and the names would need to be read from the palette files directly. not impossible to do but also not something that is doable in a few hours.

  14. changed the title [-]Custom color palettes[/-] [+]deleting a custom color palette (one of 20) changes effects that use another custom palette[/+] on Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions