diliup gabadamudalige wrote:
pygame.event.clear() before exiting the function somehow when I removed that line the error stopped.
That would definitely be it! You were throwing away any events that came in between calling event.get() and reaching the end of your function. Not a good idea when you rely critically on seeing *all* key up events. I don't know why you thought you needed to call event.clear(), but whatever your reason was, it was probably wrong.
So may be I had to keep all the unused events for the next time the loop was entered. Is that correct?
Exactly correct. -- Greg