SDL 2.0 will not initialize. Error: "Failed to connect to server" Mir "

I am running Ubuntu 14.04 and using Eclipse CDT.

In my program, I try to initialize the SDL, and if it does not initialize, then it throws an error, but SDL_GetError () returns "Failed to connect to the World server. I am sure the SDL is installed correctly, as I can successfully initialize SDL in another project.

These are the libraries I'm using: http://i.imgur.com/SS1mjzQ.png

#include <SDL2/SDL.h>
#include <iostream>

int main(int argc, char* args[]) {
  if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
    std::cout << SDL_GetError() << std::endl;
  }

  return 0;
}

      

+3


source to share


3 answers


bash $export DISPLAY=:0

Setting the DISPLAY runtime variable fixes this for me - a typical X Windows loss, unable to default to your local display (destined for remote displays) that you would only know if you were going to X11 summer camp.

Complete working example in bash:



(cd /tmp && g++ -xc++ - -lSDL2 && (DISPLAY=:0 ./a.out; echo \$? = $?)) <<.
#include <SDL2/SDL.h>
#include <iostream>

int main() {
  if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
    std::cout << SDL_GetError() << std::endl;
    return 1;
  }
  return 0;
}
.

      

$? = 0

+1


source


Does the environment you are working in have a windowing system?
This error came up for me when I run tests initializing SDL2 on Travis CI using Ubuntu 14.04. Based on what I was able to gather from further testing and hints I got from google searches SDL_Init

when initializing the SDL, if passed in SDL_INIT_VIDEO

(which you do implicitly with SDL_INIT_EVERYTHING

) it will try and connect to your machine's windows system.
So maybe try:

SDL_Init(0)

      

and then initialize other subsystems later:



SDL_InitSubSystem(SDL_INIT_EVERYTHING)

      

If you remember that you have to log out of every subsystem you initialize in this case, that's just technical. You would do it like this:

SDL_QuitSubSystem(SDL_INIT_EVERYTHING)

      

0


source


I had this error when I used gcc to compile. When I used g ++ to compile it fixes the problem. The Lazy Foo tutorial also recommends using g ++ for compilation.

If you're having this problem, you can try using g ++ to compile and see if that fixes the problem.

0


source







All Articles