It's almost completely dependent on the masks construction. I never had problems with my n95 from 3m, but the kn95 I have is impossible to wear with glasses no matter how I fit it.
The surgical mask a friend got for me in March looks near identical to the pack of masks I got recently besides the color but the one she got me fogs up my glasses while the pack I have now never does.
The top of the mask, and the nose-bridge of the safety glasses, compete for the same location on the bridge of my nose.
If I layer them so that the mask touches my skin, and the eye glasses rest on the mask, I have no problem with fogging.
If I layer them the other way: the eye glasses' bridge directly on my skin, and the top of the mask resting on the eye glasses' bridge, I get fog.
Maybe you're experiencing this?
I usually avoid this simply by putting my eye glasses on after my mask is in place.