When I change vertical size of XNA game window to minimum, it throws ObjectDisposedException for spritebatch, why?

主宰稳场 提交于 2020-02-04 01:15:30

问题


When I resize the game window and the viewport's height becomes 0, GC disposes of spritebatch, I think. Is this what happens? How do I prevent this?


回答1:


Form gameForm = (Form)Form.FromHandle(Window.Handle);
gameForm.MinimumSize = new System.Drawing.Size(800, 600);

Short and sweet!




回答2:


I had this same problem and some quick debugging shows that XNA calls UnloadContent and then LoadContent again to reinitialise resources; my guess it it loses the GraphicsDevice or something, hence the reload.

Creating things pertaining to the GraphicsDevice in LoadContent solves this problem.

Now, for this particular case, setting a minimum size is a good idea, but I don't know if this is a portable solution between Xbox and Windows. However, there might be other situations in which something similar occurs, where UnloadContent is called, so it's probably best to adhere to this practice.



来源:https://stackoverflow.com/questions/12732055/when-i-change-vertical-size-of-xna-game-window-to-minimum-it-throws-objectdispo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!