[Bug] IndexError in nodes_sampler.py when using bg_images with context window sampling

Open
#1,997 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python

Research direction

Start by reading WanVideoAnimateEmbeds.process and the context-window sampling path around nodes_sampler.py line 1903, where image_cond[:, c] raises the reported IndexError. Reproduce with bg_images connected and WanVideoContextOptions enabled, then trace how the looping path builds the conditioning sequence. Done when the workflow samples without out-of-bounds latent indices; add or run a regression test if the project has one.

Written by the indexing model from the issue text.

Description

Describe the bug

When using the WanVideoAnimateEmbeds node with bg_images connected, the workflow crashes during the sampling stage with an IndexError. This appears to happen when context windowing is active, as the sampler attempts to access latent indices that are out of bounds for the image_cond tensor.

Error Log

Plaintext

IndexError: index 15 is out of bounds for dimension 0 with size 2

  File "/root/ComfyUI/execution.py", line 525, in execute
    ...
  File "/root/ComfyUI/custom_nodes/ComfyUI-WanVideoWrapper/nodes_sampler.py", line 1903, in process
    partial_img_emb = image_cond[:, c].to(device)
Reproduction Steps
  1. Create a WanAnimate workflow.
  2. Connect an image sequence to the bg_images input of the WanVideoAnimateEmbeds node.
  3. Enable WanVideoContextOptions.
  4. Run the queue.
Technical Analysis

In nodes_sampler.py (Line 1903), the code tries to slice the image_cond based on the context window indices c:

partial_img_emb = image_cond[:, c].to(device)

However, in WanVideoAnimateEmbeds.process, when looping is True (triggered by context options), the logic for bg_images does not seem to correctly concatenate the background latents into the ref_latent sequence that eventually becomes image_cond.

Specifically:

  • If looping is True, ref_latent is initialized only with ref_latent_masked (usually size 1 or 2 in the temporal dimension).
  • The sampler then tries to access indices like 15 from a tensor that only has a size of 2, causing the IndexError.
Dominant language
Python
Stars
6.8k
Forks
712
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from kijai/ComfyUI-WanVideoWrapper

All issues in kijai/ComfyUI-WanVideoWrapper

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.