So I want to add a menu entry for each 'T' in an array, but when I do the following I get this error:

"X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 12 (X_ConfigureWindow)
Value in failed request: 0x0
Serial number of failed request: 628
Current serial number in output stream: 628"

and my code is:

Code :
int menu, subadd, subrem;
 
subadd = glutCreateMenu(processMenuEvents);
	glutAddMenuEntry("Teapot",TEAPOT);
 
 
	if(objList[1][0]!='N'){
		subrem = glutCreateMenu(processMenuEvents);
 
		int i = 0;
		for(i=0; i<=40; i++){
			if(objList[i][0]!='N'){
				char name[10];
				name[0] = objList[i][0];
				name[1] = objList[i][1];
				glutAddMenuEntry(name,50+i);
			}
			else i=41;
		}
	}
 
menu = glutCreateMenu(processMenuEvents);
	glutAddSubMenu("Add Object",subadd);
	glutAddSubMenu("Remove Object",subrem);
	glutAttachMenu(GLUT_RIGHT_BUTTON);

Now before I add anything to that array I get a very tall, incredibly thin submenu. But if I touch the submenu having added something I get that error.