I had a very scary experience yesterday. I usually leave my gun in its case behind the bed during the night. I was cleaning it prior to going to sleep and I just left it in the night stand and didn't bother putting it back in its case under the bed. Somewhere during the night around 3-4AM I woke up unaware that I was holding the gun and aiming it at the closet while slightly propped up in bed.

Imagine the guy in the picture above holding a gun on the right hand. That was me. Scary stuff!
I have woken up before in a prone position with my head up high not touching the pillow as if I had heard something and then realize I wake up in that posture. But yesterday was in a whole new different level. I had never grabbed anything near me that could make it such a dangerous situation. Fortunately I keep my gun loaded but not cocked and even if I had pressed the trigger nothing would come out unless I had cocked it in my sleep.
I don't recall if my finger was in the trigger, and the closet shares a wall with the laundry room which shares the backstop wall with the bathroom. I wasn't pointing it at any place that would be dangerous for a stray bullet or that had a risk of having a human in its way, but still.
Has anyone had a experience like this before? I don't recall if I was even dreaming and I am completely unaware of the events that led to me grabbing it and pointing it to the closet.
Some input would be appreciated. Just in case, I put it back in its box and locked it with a simple lock

I figure if I have to use dexterity to and add some extra steps I might be awake in the future if I ever find myself in the same position but I am still freaked out.