Skip to content

Reset Segments does not respect 'Make a segment for each output' #4136

Closed

Description

@DedeHai

What happened?

when 'Make a segment for each output' is checked I would expect reset segments to set it to that default instead of just deleting all segments.

To Reproduce Bug

check the setting, setup some segments and reset them.

Expected Behavior

see 'What happened?'

Install Method

Binary from WLED.me

What version of WLED?

0.14

Which microcontroller/board are you seeing the problem on?

ESP32-C3

Relevant log/trace output

No response

Anything else?

No response

Code of Conduct

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

Activity

  1. added
    confirmed
    on Oct 5, 2024
  2. softhack007 commented on Nov 22, 2024

    @softhack007
    Member

    Might be good to unterstand what's going on before we release 0.15.0-RC1 #4287

  3. blazoncek commented on Nov 25, 2024

    @blazoncek
    Contributor

    This behaviour is present since introduction of multistrip in 2021.

  4. netmindz commented on Nov 27, 2024

    @netmindz
    Member

    If this isn't a regression, then I would vote to remove this as a blocking issue for the 0.15.0 release

  5. softhack007 commented on Nov 27, 2024

    @softhack007
    Member

    If this isn't a regression, then I would vote to remove this as a blocking issue for the 0.15.0 release

    I agree

  6. blazoncek commented on Nov 27, 2024

    @blazoncek
    Contributor
    reset.mov

    If you decide you need it.

  7. modified the milestones: 0.15.2, 0.15.3 on Nov 8, 2025
  8. modified the milestones: 0.15.4, 0.15.5 on Mar 8, 2026
  9. DedeHai commented on Jun 21, 2026

    @DedeHai
    CollaboratorAuthor

    @coderabbitai is this still an issue in current main code? if so what is the simplest fix?

  10. coderabbitai commented on Jun 21, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/bin/bash
    # Fetch issue details
    gh issue view 4136 --repo wled/WLED --json title,body,comments | jq '.'

    Length of output: 4567


    🏁 Script executed:

    #!/bin/bash
    # Look at PR `#4287` that was referenced
    gh pr view 4287 --repo wled/WLED --json title,body,files | jq '.'

    Length of output: 699


    🏁 Script executed:

    #!/bin/bash
    # Search for reset segments functionality
    rg -n "resetSegments\|makeSegmentDefault\|segmentBounds\|autoSegments\|autoCreateSegments" --type cpp -C3
    
    # Also search for the "Make a segment for each output" setting
    rg -n "autoSegments\|auto_segments\|e131Multicast\|multistrip\|autoCreateSeg" --type cpp -C3

    Length of output: 559


    🏁 Script executed:

    #!/bin/bash
    # Search for the reset segments UI action / function
    rg -n -i "resetSeg\|reset.*seg\|seg.*reset" --type cpp -C5

    Length of output: 366


    🏁 Script executed:

    #!/bin/bash
    # Try searching without --type flag
    rg -n "resetSegments\|autoSegments\|autoCreateSeg" -C3
    
    rg -n -i "reset.*seg\|seg.*reset" -C3

    Length of output: 384


    🏁 Script executed:

    #!/bin/bash
    # Find what source files exist
    fd -e cpp -e h -e ino | head -50

    Length of output: 2056


    🏁 Script executed:

    #!/bin/bash
    # List files in wled00
    fd -e cpp -e h -e ino . wled00/
    
    # Search for reset segment logic in wled00
    grep -rn "resetSegments\|autoSeg\|makeSegment\|segmentsFrom\|Segment_Output\|each.*output\|output.*seg" wled00/ -C3

    Length of output: 11191


    🏁 Script executed:

    #!/bin/bash
    # Search for the specific functionality - "Make a segment for each output" 
    grep -rn "autoSeg\|makeEachSeg\|each_seg\|eachSeg\|auto_seg" wled00/ -C3
    
    # Search for reset/default segment functions
    grep -rn "resetSeg\|defaultSeg\|initSeg" wled00/ -C3

    Length of output: 7177


    🏁 Script executed:

    #!/bin/bash
    # Get the full resetSegments and makeAutoSegments functions
    sed -n '1960,2060p' wled00/FX_fcn.cpp

    Length of output: 4070


    🏁 Script executed:

    #!/bin/bash
    # Find where "Reset Segments" is called from the UI / JSON API
    grep -rn "resetSeg\|RST\|\"rs\"\|resetpresets\|clearSegs\|reloadsegs" wled00/ -C3 | grep -v "ota_update\|wled.cpp\|FX_fcn\|FX_2D\|FX.h"

    Length of output: 10881


    🏁 Script executed:

    #!/bin/bash
    # Find where the "Reset Segments" button calls from - look in json.cpp and the segment UI
    grep -n "resetSeg\|\"seg\"\|clearSeg\|seg.*clear\|\"on\"\|rSeg\|rs\"" wled00/json.cpp | head -60
    
    # Also look for where segments are reset via JSON API (the main segment reset endpoint)
    grep -n "resetSegments\|makeAutoSegments" wled00/json.cpp wled00/led.cpp wled00/wled.cpp wled00/cfg.cpp

    Length of output: 1718


    🏁 Script executed:

    #!/bin/bash
    # Look for the "Reset" segment button in the UI HTML
    grep -n -i "reset\|\"rs\"\|rseg\|reset_seg" wled00/data/index.htm | head -30

    Length of output: 618


    🏁 Script executed:

    #!/bin/bash
    # Find the rSegs() JS function
    grep -n "rSegs\|function rS" wled00/data/index.htm | head -20
    
    # Get the surrounding context of rSegs
    grep -n -A 15 "function rSegs" wled00/data/index.htm

    Length of output: 526


    🏁 Script executed:

    #!/bin/bash
    # Search all files for rSegs function definition
    grep -rn "function rSegs\|rSegs\s*=" wled00/data/
    
    # Also check if there's a separate JS file
    fd -e js . wled00/data/

    Length of output: 553


    🏁 Script executed:

    #!/bin/bash
    # Look at the full index.htm for rSegs context (the function may be inline but minified)
    grep -n "rSegs" wled00/data/index.htm
    # Check the JavaScript section around line 284
    sed -n '270,300p' wled00/data/index.htm

    Length of output: 1642


    🏁 Script executed:

    #!/bin/bash
    # Get the rSegs function from index.js
    sed -n '2805,2830p' wled00/data/index.js

    Length of output: 664


    🏁 Script executed:

    #!/bin/bash
    # Look at json.cpp around the segment processing / suspension area
    grep -n "suspend\|resume\|makeAuto\|resetSeg\|seg\b" wled00/json.cpp | head -40
    
    # Get segment processing context in deserializeState
    sed -n '450,530p' wled00/json.cpp

    Length of output: 5709



    @DedeHai — yes, this is still present in current main. Here's the full picture:


    Root cause

    rSegs() in wled00/data/index.js (line 2810) manually constructs a JSON payload that always resets to a single full-strip segment:

    var obj = {"seg":[{"start":0,"stop":ledCount,"sel":true}]};
    // ...
    for (let i=1; i<=lSeg; i++) obj.seg.push({"stop":0}); // delete all others
    requestJson(obj);

    It completely bypasses strip.autoSegments. The backend function makeAutoSegments(true) already does the right thing for both cases:

    • autoSegments = true → creates one segment per bus
    • autoSegments = false → calls resetSegments() → single full-strip segment

    But rSegs() never calls it.


    Simplest fix — two small changes

    1. wled00/json.cpp — add a "rSeg" key handler in deserializeState() (after the existing segVar block, around line ~510):

    if (root[F("rSeg")] | false) {
      strip.suspend();
      strip.waitForIt();
      strip.makeAutoSegments(true);  // respects autoSegments flag
      strip.resume();
      stateChanged = true;
    }

    2. wled00/data/index.js — simplify rSegs() to use the new key (removes the manual segment construction entirely):

    var cnfrS = false;
    function rSegs()
    {
      var bt = gId('rsbtn');
      if (!cnfrS) {
        bt.style.color = "var(--c-r)";
        bt.innerHTML = "Confirm reset";
        cnfrS = true; return;
      }
      cnfrS = false;
      bt.style.color = "var(--c-f)";
      bt.innerHTML = "Reset segments";
      requestJson({"rSeg": true});
    }

    Why this is safe

    • No circular recursion: makeAutoSegments(true) when autoSegments=true creates per-bus segments directly without calling resetSegments().
    • OTA / low-heap paths unaffected: those still call strip.resetSegments() directly.
    • deserializeState() already uses strip.suspend() / strip.waitForIt() / strip.resume() for segment mutations — same pattern applies here.
    • The JS simplification also fixes the minor issue that the old code passed an incorrect segment count when segments had been added/removed.
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

    bugconfirmed

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions