DiddiLeija / diddi-and-the-bugs

Diddi and the Bugs, my GameOff 2021 game.
https://diddileija.itch.io/diddi-and-the-bugs
MIT License
7 stars 3 forks source link

Issues with restarting the game #20

Closed DiddiLeija closed 2 years ago

DiddiLeija commented 2 years ago

This is a bug I found while confirming #18. When you loose, pause or win, it's impossible to use the R key to restart. I don't remember this happened with old Pyxel releases, so maybe it's an upstream thing?

HarshNarayanJha commented 2 years ago

R key is currently working for me in all scenarios. Pyxel 1.5.8

DiddiLeija commented 2 years ago

So this is an upstream bug (the current requirement is pyxel==1.6.1).

HarshNarayanJha commented 2 years ago

Will fix this, but maybe after my online exams (today's exam and I have 2 hours left to study!) Thanks

DiddiLeija commented 2 years ago

Absolutely no worries for the time, and I hope you will do it well on your exams!

DiddiLeija commented 2 years ago

The exact exception I had is:

C:\Users\Diego Ramirez\diddi-and-the-bugs>main.py
Traceback (most recent call last):
  File "C:\Users\Diego Ramirez\diddi-and-the-bugs\main.py", line 137, in update
    self.__init__()
  File "C:\Users\Diego Ramirez\diddi-and-the-bugs\main.py", line 124, in __init__
    self.enemies = [Enemy() for sth in range(200)]
  File "C:\Users\Diego Ramirez\diddi-and-the-bugs\main.py", line 124, in <listcomp>
    self.enemies = [Enemy() for sth in range(200)]
  File "C:\Users\Diego Ramirez\diddi-and-the-bugs\main.py", line 46, in __init__
    self.aspect = random.choice(self.possible_enemies)
  File "C:\Users\Diego Ramirez\AppData\Local\Programs\Python\Python39\lib\random.py", line 346, in choice
    return seq[self._randbelow(len(seq))]
RecursionError: maximum recursion depth exceeded while calling a Python object

C:\Users\Diego Ramirez\diddi-and-the-bugs>

When we call R, we call App.__init__ again:

https://github.com/DiddiLeija/diddi-and-the-bugs/blob/b1dad49f20d55b8445901ca5eeb8b8ff8c192aa9/main.py#L135-L144

This happens in the update function.

So, I suppose Pyxel has changed its way to call update and draw in version 1.6, generating some kind of recursion. Then, easy things like getting random.choice will crash.

HarshNarayanJha commented 2 years ago

Ok! I fixed this... will open a PR tomorrow morning!

DiddiLeija commented 2 years ago

Thanks! Just remember to add a Closes #20 sentence with the first post of the PR!

HarshNarayanJha commented 2 years ago

This bug was caused by recalling the pyxel.run() method, which causes a recursion here's the bugfix PR: https://github.com/DiddiLeija/diddi-and-the-bugs/pull/22