Skip to content

Commit

Permalink
Fix Screens.Hash() to work for screens without roots (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohansingh authored Sep 3, 2021
1 parent 8f0ad3b commit b7604d7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions encode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@ func ScreensFromImages(images ...image.Image) *Screens {
// testing whether two render trees are exactly equivalent, without having to
// do the actual rendering.
func (s *Screens) Hash() ([]byte, error) {
if len(s.roots) == 0 {
return nil, errors.New("hash isn't supported for screens without roots")
}

hashable := struct {
Roots []render.Root
Delay int32
Roots []render.Root
Images []image.Image
Delay int32
}{
Roots: s.roots,
Delay: s.delay,
}

if len(s.roots) == 0 {
// there are no roots, so this might have been a screen created directly
// from images. if so, consider the images in the hash.
hashable.Images = s.images
}

sum, err := hashstructure.Hash(hashable, hashstructure.FormatV2, nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit b7604d7

Please sign in to comment.