I’m running the Eclipse IDE on Ubuntu 12.04 with the Valgrind plugin. I’ve been working on a game in C++ for quite some time, and I seem to have a memory error somewhere. Normally, I trace these with Valgrind. However, glut fails to initialize when I run valgrind. I should note that the game initializes without a problem when I’m not using valgrind. The code for my main function is as follows:
int main(int argc, char** argv) {
char windowTitle[12] = "Game Window";
printf("Initializing Glut...\n");
glutInit(&argc, argv);
printf("Glut initialized!\n");
alutInit(&argc, argv);
Game_Object* game = new Game_Object(windowTitle, 1200, 675, argc, argv);
delete game;
printf("game ended\n");
return 0;
}
The resulting output to the console is:
Initializing Glut
freeglut (/home/dsnettleton/Documents/Programming/Eclipse/workspace/Plutoids/Debug/Plutoids): failed to open display ''
Obviously, the program isn’t getting very far with valgrind running.
It’s really disheartening to be in such a final stage of my development, only to get stuck trying to weed out a memory error. What might be keeping glut from initializing, and what can I do to fix the problem?
This is my guess: your IDE is probably missing the
$DISPLAYenvironment variable. Somewhere you have to configure the environment to set$DISPLAYbefore launching Valgrind.Launch a terminal and
echo $DISPLAY. Its value is probably:0.0.In the worst case, I’d try using
setenv()inside the C code or set DISPLAY in the command line that launches Valgrind (none of these cases was tested, they may not work).