Skip to content

Background image flickers when loading new image #105

@lebaudantoine

Description

@lebaudantoine

Issue: Backgroundf image flickers when loading new image

Description
When loading a new background image in loadAndSetBackground, the currently active background is removed before the new image has been set. This causes a short but noticeable flicker (background disappears briefly, then reappears with the new image).

On my MacBook, the flicker is barely noticeable. However, users with slower CPUs, GPUs, or limited RAM experience a more visible blink that can last up to half a second or longer.

Code Snippet

async loadAndSetBackground(path: string) {
  if (!this.backgroundImageAndPath || this.backgroundImageAndPath?.path !== path) {
    const img = new Image();

    await new Promise((resolve, reject) => {
      img.crossOrigin = 'Anonymous';
      img.onload = () => resolve(img);
      img.onerror = (err) => reject(err);
      img.src = path;
    });

    const imageData = await createImageBitmap(img);
    this.backgroundImageAndPath = { imageData, path };
  }
  this.gl?.setBackgroundImage(this.backgroundImageAndPath.imageData);
}

Problem
Even before setBackgroundImage() is called with the new image data, the previously set background seems to be destroyed. Adding a debug stop confirmed that the old background is gone while the new one is still loading.

Enregistrement.de.l.ecran.2025-09-17.a.22.44.38.mov

Expected Behavior

  • The old background should remain visible until the new one has been fully loaded.
  • Once ready, the new background should smoothly replace the previous one, avoiding any flicker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions