From b70c9d0959efee3ece9c23a91e4b2c3a5f9f0753 Mon Sep 17 00:00:00 2001 From: kijai <40791699+kijai@users.noreply.github.com> Date: Wed, 15 Apr 2026 01:17:13 +0300 Subject: [PATCH] Edge case guards --- comfy_extras/nodes_sam3.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/comfy_extras/nodes_sam3.py b/comfy_extras/nodes_sam3.py index 0ea5ac1f7..b7be5e3a3 100644 --- a/comfy_extras/nodes_sam3.py +++ b/comfy_extras/nodes_sam3.py @@ -70,6 +70,8 @@ def _refine_mask(sam3_model, orig_image_hwc, coarse_mask, box_xyxy, H, W, device mask_h, mask_w = coarse_mask.shape[-2:] mx1, my1 = int(cx1 / W * mask_w), int(cy1 / H * mask_h) mx2, my2 = int(cx2 / W * mask_w), int(cy2 / H * mask_h) + if mx2 <= mx1 or my2 <= my1: + return _coarse_fallback() mask_logit = coarse_mask[..., my1:my2, mx1:mx2].unsqueeze(0).unsqueeze(0) for _ in range(iterations): coarse_input = F.interpolate(mask_logit, size=(1008, 1008), mode="bilinear", align_corners=False) @@ -248,6 +250,8 @@ class SAM3_Detect(io.ComfyNode): all_masks.append(torch.zeros(H, W, device=comfy.model_management.intermediate_device())) pbar.update(1) + idev = comfy.model_management.intermediate_device() + all_masks = [m.to(idev) for m in all_masks] mask_out = torch.cat(all_masks, dim=0) if individual_masks else torch.stack(all_masks) return io.NodeOutput(mask_out, all_bbox_dicts) @@ -297,7 +301,7 @@ class SAM3_VideoTrack(io.ComfyNode): pbar = comfy.utils.ProgressBar(N) text_prompts = None - if conditioning is not None: + if conditioning is not None and len(conditioning) > 0: text_prompts = [(emb, mask) for emb, mask, _ in _extract_text_prompts(conditioning, device, dtype)] elif initial_mask is None: raise ValueError("Either initial_mask or conditioning must be provided")