Skip to content

Commit

Permalink
Fix race condition on screenshot generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Chapron committed Apr 11, 2024
1 parent fbf654d commit e87d14d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.5] - 2024-04-11

### Fixed

- Fix race condition on screenshot generation

## [0.8.4] - 2024-04-10

### Fixed
Expand Down
7 changes: 6 additions & 1 deletion speculos/mcu/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(self, model: str):
self.screenshot_pixels: PixelColorMapping = {}
self.default_color = 0
self.draw_default_color = False
self.reset_screeshot_pixels = False
self._public_screenshot_value = b''
self.current_data = b''
self.recreate_public_screenshot = True
Expand Down Expand Up @@ -112,7 +113,7 @@ def draw_rect(self, x0: int, y0: int, width: int, height: int, color: int) -> Li
self.default_color = color
self.draw_default_color = True
self.pixels = {}
self.screenshot_pixels = {}
self.reset_screeshot_pixels = True
return [TextEvent("", 0, 0, 0, 0, True)]

for x in range(x0, x0 + width):
Expand All @@ -129,6 +130,7 @@ def _get_image(self) -> bytes:
return bytes(data)

def _get_screenshot_iobytes_value(self) -> bytes:
print("_get_screenshot_iobytes_value")
# Get the pixels object once, as it may be replaced during the loop.
data = self._get_image()

Expand All @@ -141,6 +143,9 @@ def take_screenshot(self) -> Tuple[Tuple[int, int], bytes]:
return self.current_screen_size, self._get_image()

def update_screenshot(self) -> None:
if self.reset_screeshot_pixels:
self.screenshot_pixels = {}
self.reset_screeshot_pixels = False
self.screenshot_pixels.update(self.pixels)

def update_public_screenshot(self) -> None:
Expand Down

0 comments on commit e87d14d

Please sign in to comment.