A crash has 2 elements: The crash reason, like a bug somewhere in the script that overwrites memory, and the crash trigger which produces the error message. Normally both are the same, but not always, and then is the crash hard to find. The trigger can be a completely harmless line in a function. If that function is modified, it crashes somewhere else.

Keep the state where it always crashes when you press P, and try to find the code line that triggers the crash. This often helps to find the bug, by looking at variables or pointers used in that line.