When the five outer sense gates close, the mind loses the anchoring effect of reality, perception loses coherence and continuity.
Drifting dreams begin.
If you can keep consciousness firm and still, like in meditation, you attain consistent hallucinations instead.
This is the manifestation of the polluted base seeds or karma.
The challenge is to clean the seeds and clear the karma to attain full nirvana.