Display Settings and Game Restart

Why do some games require a restart after changing display settings while others can change them instantly?

Games may require restarts for display setting changes due to several technical factors:

Engine Architecture

Some game engines initialize critical systems based on the display settings during startup. These might include:

  • Memory allocation for rendering buffers
  • Creation of rendering contexts and pipelines
  • Loading of shaders and textures at specific resolutions
  • Setup of post-processing effects

Changing these settings while the game is running could require complex reconstruction of these systems, which might be risky or impractical.

Resource Management

Games often load and optimize resources based on the initial display settings:

class ResourceManager {
  std::vector<SDL_Texture*> TextureCache;
  SDL_Renderer* Renderer;
  int CurrentWidth;
  int CurrentHeight;

public:
  ResourceManager(
    SDL_Renderer* R, int W, int H
  ) : Renderer{R},
      CurrentWidth{W},
      CurrentHeight{H}
  {
    // Resources loaded and optimized for
    // this resolution
    LoadResources();
  }

private:
  void LoadResources() {
    // Load textures at appropriate sizes
    // for current resolution
    // ...
    
    // Calculate mipmap chains
    // ...
    
    // Set up render targets
    // ...
  }
};

Changing resolution might require reloading these resources, which could be time-consuming and memory-intensive during gameplay.

Safe Implementation

For games that do support instant changes, careful implementation is required:

#include <SDL.h>

class DynamicRenderer {
  SDL_Window* Window;
  SDL_Renderer* Renderer;

  bool RecreateRenderer() {
    // Destroy old renderer and resources
    if (Renderer) {
      SDL_DestroyRenderer(Renderer);
    }

    // Create new renderer for current settings
    Renderer = SDL_CreateRenderer(
      Window, -1,
      SDL_RENDERER_ACCELERATED
    );

    return Renderer != nullptr;
  }

public:
  bool ChangeDisplayMode(
    const SDL_DisplayMode& Mode) {
    // Apply new mode
    if (SDL_SetWindowDisplayMode(
      Window, &Mode) < 0) {
      return false;
    }

    // Recreate renderer for new settings
    return RecreateRenderer();
  }
};

The choice between instant changes and requiring a restart often comes down to balancing technical complexity against user convenience.

Display Modes

Learn how to manage screen resolutions and refresh rates in SDL games using display modes.

Questions & Answers

Answers are generated by AI models and may not have been reviewed. Be mindful when running any code on your device.

Handling Unsupported Display Modes
What happens if a player has a monitor that doesn't support the display mode our game wants to use?
Scaling Retro Games
If I'm making a retro-style game that uses a low resolution, how can I make it look good on modern high-resolution displays?
Display Mode Safety Timer
How can we implement a system that reverts to the previous display mode after a timer if the user doesn't confirm the changes?
Saving Fullscreen Preferences
How can I save the player's preferred fullscreen mode and restore it the next time they launch the game?
Or Ask your Own Question
Get an immediate answer to your specific question using our AI assistant