UQcsse3200 / 2024-studio-2

MIT License
5 stars 0 forks source link

chatOverlayService null on return to game after combat. #208

Open callumreillyy opened 1 month ago

callumreillyy commented 1 month ago

Description

Discovered a bug where exiting combat while being collided with a Friendly npc causes the game to crash. Bug only occurs if player is colliding with a friendly NPC IMMEDIATELY after leaving combat. This is related to the dialogue box variable "chatOverlayService" being null when returning to old screen.

Replicate Bug

  1. Start maingame
  2. Collide with friendly NPC to start dialogue overlay
  3. Kite an enemy NPC over to the friendly NPC
  4. When enemy NPC is very close, collide with them to start combat
  5. Select "insta kill enemy" option to return to maingame
  6. Move player
  7. Game will crash with error message below

Expected Behaviour

A clear and concise description of what you expected to happen.

Error Message

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.csse3200.game.entities.EntityChatService.disposeCurrentOverlay()" because "chatOverlayService" is null

Additional Context

I believe the bug exists due to logic with game screen states, namely the use of "setOldScreen(screen, container)" after combat win which likely does not load the "chatOverlayService" variable correctly when returning to the original game screen.

Interestingly, as long as you are not colliding with a friendly NPC immediately after combat, the bug does not occur. (i.e if you called with enemy away from FNPC, then walk over to an FNPC dialogue loads as normal with no crashes). This could mean it is simply an issue with not loading the resources in the correct order.

Temporary Fix

No temp fix as of right now

EllaBerglas commented 4 weeks ago

Hey, I had this issue when I did the mini-games. Probs not the best fix but if you look at the end and begin dialogue method in NPC factory I just initialise it again where it fails. It might have even fixed your issue now. But might have a look into preserving the instance when it changes screens in sprint 3