Out of the blue today, my Macbook Pro 2015 15", running macOS Catalina 10.15.2, shut down while I was using it.
Since then, for the past half hour or so, I haven't been able to keep it on for longer than a minute or so. It either spontaneously shuts down, requiring me to manually turn it back on, or it spontaneously restarts. Now (a day later) it only spontaneously shuts down. It doesn't restart itself.
This happens when it is plugged into the charger and when it is simply running on battery. This also happens while only headphones are connected to the MacBook, or while no peripherals are connected.
Apple Diagnostics shows "No issues found."
I have tried resetting SMC and NVRAM.
Additionally, when starting up I notice weird graphical glitches, for example a white bar sometimes appears on the left side of the screen, or the apple logo repeatedly resizes itself, or a regular pattern of white rectangles appears across the whole screen.
I got a picture of that:
This flashes onto the screen after the first apple logo appears.
The Macbook does not spontaneously shut down or restart when I boot it into Recovery Mode or Safe Mode.
However, there are also graphical glitches in both of these modes; look at the terminal tabs in Recovery Mode:
Moving the mouse cursor over the tabs causes them to scintillate randomly, rectangular monochrome patterns. and glitches.
Exactly the same graphical glitch happens to Finder tabs in Safe Mode.
Why does my Macbook restart like that after I've booted it normally? How do I resolve this problem?