picking errors

Hello,
I’m trying to create a function, that returns the name, of the quad you have your mouse on(I want to do the hover thing like you can do in HTML).
But for some strange reason, I get two(or maybe more) errors.
The first one is:

This command would cause a stack underflow. The offending command isignored, and has no other side effect than to set the error flag.
And the second is:

Invalid Name parameter.

My function:

short Menu::Selected(int x, int y)
{
	GLuint selectbuf[512];
	GLint viewport[4];
	GLint hits;
	glGetIntegerv(GL_VIEWPORT, viewport);
	
	glSelectBuffer(512, selectbuf);
	glRenderMode(GL_SELECT);
	
	glInitNames();
	glPushName(0);
	
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	
	gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3] - y), 2.5, 2.5, viewport);
	gluOrtho2D(-5.0, 5.0, -5.0, 5.0);
	
	DrawMenu(true);
	
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glFlush();
	glPopName();
	
	hits = glRenderMode(GL_RENDER);
	
	GLuint *tmp;
	tmp = selectbuf;
	GLuint names = *tmp;
	cout << "Number of names on the stack: " << names << endl;
	tmp++;
	cout << "Minimum z window value: " << *tmp << endl;
	tmp++;
	cout << "Maximum z window value: " << *tmp << endl;
	cout << "hits: " << hits << endl;
	tmp++;
	cout << "First hit: " << *tmp << endl;
	if(names > 0)
		return *tmp+1;
	else
		return 0;
}

Because my code is quite identicall to the functions proces****s and pickSquares from the example picksquare.c from the OpenGL red book, it’s a mistery to me why I get these errors.
My function DrawMenu([…]) is like this:

for(int i = 0;i < x;i++)
{
dosomecalculations();
glLoadName(i);
drawsomething();
}

Could anyone help me in the right direction why it might not work?
Thanx in advance,
Hylke

I just need a hint, you don’t have to debug the hall code.
Just a clue is most probably enough.