Skip to content

saveGif() crashes when duration <= 0 (empty frame list path) #8710

@avinxshKD

Description

@avinxshKD

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • p5.strands
  • WebGL
  • DevOps, Build process, Unit testing
  • Internationalization (i18n)
  • Friendly Errors
  • Other (specify if possible)

p5.js version

main

Web browser and version

Chrome (latest stable)

Operating system

Windows 11 (should be OS-independent)

Steps to reproduce this

Steps:

  • Create any sketch.
  • Call saveGif('test', 0) (or negative duration) in setup() or from a key handler.
  • Check console.

snippet:

function setup() {
  createCanvas(100, 100);
  background(220);
  circle(50, 50, 30);

  // Repro: zero duration
  saveGif('test', 0);
  // also repros with negatives, e.g. saveGif('test', -1);
}

Console error:

TypeError: Cannot read properties of undefined (reading 'length')

Expected behavior
saveGif() should reject invalid duration early (e.g. duration must be > 0)
or gracefully handle zero captured frames without crashing.

Actual behavior
duration <= 0 leads to zero captured frames, then palette generation path assumes frames[0] exists and crashes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions