Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

It works fine in other "projects" so it has something to do with project. The project im talking about here has tons of classes but nothing with graphicsdevicemanager other than game1.cs game1.cs starts with

    GraphicsDeviceManager graphics;

then in public game1()

        graphics = new GraphicsDeviceManager(this);
        graphics.PreferredBackBufferWidth = 1024;

nope, the game is still 800x600. I have also tried adding graphics.ApplyChanges(); while I dont need it in game1 and would be calling twice, still didnt work.

HOWEVER, if I add

        graphics.PreferredBackBufferWidth = 1024;
        graphics.ApplyChanges();

to "Initialize" (graphics' init is still from game1) it works

as you can see, I can fix it by going to Initialize and wasting some resource but I wonder why this is happening ? Im sure someone else in my code doesnt interfere.(I have no idea if something like this exist in properties etc. tho)

share|improve this question
    
Why do you think doing it in Initialize wastes resources? –  William 'MindWorX' Mariager Aug 7 '12 at 3:34
    
well I dont "think" it might be incorrect, I've read it in somewhere else. Basically game1 alredy calls applychanges and you call it twice. of course, its very minimal but should avoid it when possible. What I read might be non-sense as well, I can never be sure. –  Newell Aug 7 '12 at 4:13
    
@Newell: You're quite right. See this answer for the exact details of why you shouldn't be setting the resolution in Initialize. –  Andrew Russell Aug 7 '12 at 5:45
    
are you initializing only witdh? I think you should initialize height too... –  Blau Aug 7 '12 at 9:30
    
@AndrewRussell, What exactly is bad about setting it up twice? You state it in the answer you linked, but you don't say why, but I'm very curious, as I have the creating of the GraphicsDeviceManager in the constructor, but set the resolution in Initialize in my current project. –  William 'MindWorX' Mariager Aug 7 '12 at 14:38
show 10 more comments

2 Answers

I can think of many different ways that something could be sneaking in and changing the size of your backbuffer. Here are a few guesses:

  • Something is hooking PreparingDeviceSettings and then overriding GraphicsDeviceInformation.PresentationParameters.BackBufferWidth/Height during the initial device setup. This seems likely if there is code in the project for configuring multisampling.

  • A game component has an Initialize method that is doing the same thing as your own "hack" (please don't do this) and doing the equivalent of ApplyChanges (it could be calling GraphicsDevice.Reset directly, for example).

  • The GraphicsDeviceManager class adds itself to Services. This is how Game is able to find it and use it to set up the graphics device in the first place. Perhaps something is using that as a way to go in and mess with it directly?

Probably the best way to determine when this is happening is to hook GraphicsDeviceManager.PreparingDeviceSettings or GraphicsDevice.DeviceResetting (or perhaps something else) with a blank event that contains a breakpoint (or Debugger.Break()). And then inspect the state that is being set up.

The other simple thing to do might be to just full text search your code for the number "600" or "800" and see if that helps you find the code responsible.

Another way, which is slow but will surely find the responsible code, is to step through the entire startup sequence of your game, line-by-line, in the debugger.

share|improve this answer
add comment

Okay there are a couple of basic things i would try.

First: rebuild your solution if you have already not done so.

Second (if that didnt work): try to set the window to full screen, if this works then there is a problem somewhere down your code, look through it and see if you are altering the resolution (you may be doing this in a different object/class dont forget to check them).If you found any resolution changes below the public method then comment them out and try to run again.

If that didnt work then you will have to scontinue debugging, i would recommend quickly setting up an empty project and trying to change the screen resolution, if the same problem occurs there may be something wrong with your ide setup otherwise you know that there is something wrong with your solution and will have to comb through your code to find the culprit. If that doesnt work then copy all of your code into a new project.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.