UQdeco2800 / 2021-studio-7

6 stars 2 forks source link

NullPointerException on Timer Completion #157

Closed E-Roderick closed 3 years ago

E-Roderick commented 3 years ago

Description

Issue

It seems that when the timer in the main game reaches 2:00 AM, the game crashes from a NullPointerException.

Steps to Reproduce

  1. Enter the main game area
  2. Wait until the timer reaches 2:00

Expected Behaviour

I expect that at this point the game is meant to transition into a lose screen concerning the lose via time-out fail condition.

Actual Behaviour

The game freezes for a moment before closing/crashing.

Additional Comments

This is my current call stack:

Exception in thread "main" java.lang.NullPointerException
    at com.deco2800.game.screens.maingame.MainGameTextDisplay.update(MainGameTextDisplay.java:107)
    at com.deco2800.game.generic.Component.triggerUpdate(Component.java:85)
    at com.deco2800.game.entities.Entity.update(Entity.java:253)
    at com.deco2800.game.entities.EntityService.update(EntityService.java:46)
    at com.deco2800.game.screens.maingame.MainGameScreen.render(MainGameScreen.java:107)
    at com.badlogic.gdx.Game.render(Game.java:46)
    at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:403)
    at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:143)
    at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:116)
    at com.deco2800.game.desktop.DesktopLauncher.main(DesktopLauncher.java:11)

Upon first investigation it seems the exception is coming from within update() in MainGameTextDisplay. Specifically, the first line long currentTime = ServiceLocator.getTimeSource().getTime();.

E-Roderick commented 3 years ago

It seems the update method is being called after the screen has been cleared, resulting in the getTimeSource() call returning null.

E-Roderick commented 3 years ago

Resolved with #159