Skip to content

The "Loading existing environment" message is never displayed, because the cached path omits pygame.display.update() #21

Description

@dmccoystephenson

Summary

When a requested environment is already recorded in environments.json, main.py:67 draws the text "Loading existing environment, please wait..." onto the display surface but never flushes it:

if env_key in environments:
    graphik.drawText("Loading existing environment, please wait...", displayWidth/2, displayHeight/2, 20, "white")
    env_id = environments[env_key]["environment_id"]
    try:
     environment = environmentService.get_environment_by_id(env_id)

No pygame.display.update() follows on the success path. The next update on that path is main.py:124, inside the render loop — and it is preceded by gameDisplay.fill(white) at main.py:122, which erases the message before it is ever presented. The message is therefore drawn to a surface that is cleared before the first flip.

Contrast with the creation path

The sibling branch does flush, at main.py:80-81:

graphik.drawText("Creating environment, please wait...", 400, 400, 20,"white")
pygame.display.update()

The two branches are intended to be parallel; only one of them actually presents its message.

Why it matters

Loading a cached environment issues a blocking call to Viron's get_environment_by_id, followed by a blocking get_locations_in_environment at main.py:120. For a large grid this is exactly the interval during which the user needs feedback, and the window instead shows an unpainted surface. The error path at main.py:74-76 does call update(), so a failure is visible while the wait that precedes it is not.

Suggested resolution

Add pygame.display.update() immediately after the drawText call at main.py:67, matching the creation path.

A secondary consideration: the creation path hardcodes the text position as 400, 400 rather than displayWidth/2, displayHeight/2 as the cached path does. Aligning the two would be a reasonable part of the same change, though it is cosmetic and only differs once displayWidth / displayHeight stop being 800.

Acceptance criteria

  • The cached-environment path presents its progress message before the blocking service call is issued.
  • The behavior is verified by a run against a Viron instance with a grid size already present in environments.json, or by a headless run with the Viron services stubbed, asserting that pygame.display.update() is called before get_environment_by_id.

This issue body was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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