-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
When the current game instance exceeds its round-to-live (rtl) limit and the game fails to launch during the following restart, the spectator crashes.
2024-08-18 01:05:41,032 INFO Game instance has reached rtl limit, restart required
2024-08-18 01:05:41,043 INFO Quitting existing game instance
2024-08-18 01:05:47,638 INFO Starting new game instance
2024-08-18 01:06:08,705 ERROR Game instance was not launched, retrying
Traceback (most recent call last):
File "BF2AutoSpectator\spectate.py", line 778, in
File "BF2AutoSpectator\spectate.py", line 377, in run
File "BF2AutoSpectator\game\instance_manager.py", line 204, in is_game_message_visible
File "BF2AutoSpectator\common\utility.py", line 383, in ocr_screenshot_game_window_region
AttributeError: 'NoneType' object has no attribute 'rect'
[2448] Failed to execute script 'spectate' due to unhandled exception!
2024-08-18 01:06:09,759 WARNING Disconnected from controller
Without a running game instance, it should never get to a part of the code that takes screenshots.
The issue is likely related to the rtl restart requirement being reset immediately after quitting the existing game instance (regardless of whether it was quit successfully):
BF2AutoSpectator/BF2AutoSpectator/spectate.py
Lines 299 to 307 in 7b18b7b
| # Quit out of current instance | |
| logger.info('Quitting existing game instance') | |
| gis.set_rtl_restart_required(False) | |
| if gim.quit_instance(): | |
| logger.debug('Successfully quit game instance') | |
| else: | |
| # If quit was not successful, switch to error restart | |
| logger.error('Quitting existing game instance failed, switching to killing process') | |
| gis.set_error_restart_required(True) |
When launching the new game instance later fails, the main loop starts over.
BF2AutoSpectator/BF2AutoSpectator/spectate.py
Lines 352 to 354 in 7b18b7b
| elif not got_instance: | |
| logger.error('Game instance was not launched, retrying') | |
| continue |
But because the rtl restart flag has already been reset, none of the conditions which would trigger a game instance launch are met.
BF2AutoSpectator/BF2AutoSpectator/spectate.py
Lines 295 to 296 in 7b18b7b
| # Stop existing (and start a new) game instance if required | |
| if gs.stopped() or gis.rtl_restart_required() or gis.error_restart_required(): |
It's probably a good idea to add a check there if the game window is not None and the corresponding pid is still running, but the bug should be fixed just by changing the rtl restart flag reset. Regardless, it would be a good opportunity to move the remaining logic related to the BF2 window/pid from the main loop into the instance manager.