Had you been playing for an extended period of time when this happened?
This sounds like an exact description of what happened to me when I played for several hours and ran into the crash box entity.
After an extended play session the game will flash your screen black several times before spawning an entity (appearing as a black censor box that can be seen through walls) that follows you around and will crash the game if you touch it; I've been calling it the "Touch Grass Demon" since my spouse referred to it as such lol.