Baekalfen/PyBoy

Game image differs after saving and loading state

DavidSteinhart opened this issue · 4 comments

I tried saving and loading a state, but the resulting images differ. Mario shows a different animation frame. Might be related to #99

from pyboy.utils import WindowEvent
import pyboy as pyboy
import numpy as np
import io

# Load Super Mario Land and progress to start of game
boy = pyboy.PyBoy('SuperMarioLand1.gb')
boy.set_emulation_speed(0)
for i in range(100):
      boy.tick()
boy.send_input(WindowEvent.PRESS_BUTTON_START)
boy.tick()
boy.send_input(WindowEvent.RELEASE_BUTTON_START)
for i in range(20):
      boy.tick()

boy.send_input(WindowEvent.PRESS_ARROW_RIGHT)
for i in range(50):
      boy.tick()

screen_before = boy.botsupport_manager().screen().screen_image()
array_before = boy.botsupport_manager().screen().screen_ndarray()

file_like_object = io.BytesIO()
boy.save_state(file_like_object)
file_like_object.seek(0)
boy.load_state(file_like_object)

screen_after = boy.botsupport_manager().screen().screen_image()
array_after = boy.botsupport_manager().screen().screen_ndarray()

screen_before.show()
screen_after.show()
print(np.array_equal(array_before, array_after))  # False

mario_before
mario_after

The two states seem to synchronize again after calling boy.tick() once.

It's likely just the screen which needs to be flushed. Definitely a bug, just a hint, if someone wants to help me fix it

the more more ,the less less

This appears to have been fixed in 1.4. The test code returns True and the images shown match.