Program: 58434
Project: 58434
Buggy source:
/** 
 * Renders an item in the context menu and recursively starts rendering its sub-menus if there are any
 * @param gl
 * @param subMenu
 * @param entry
 * @param xPosition
 * @param yPosition
 */
private void renderItem(GL gl,SubMenu subMenu,IContextMenuEntry entry,float xPosition,float yPosition){
  AContextMenuItem item=(AContextMenuItem)entry;
  Integer itemID=hashContextMenuItemToUniqueID.get(entry);
  if (itemID == mouseOverElement || isSubElementSelected(item))   renderHighlighting(gl,subMenu,yPosition);
  gl.glColor4f(1,1,1,0);
  int iPickingID=pickingManager.getPickingID(masterGLView.getID(),EPickingType.CONTEXT_MENU_SELECTION,itemID);
  gl.glPushName(iPickingID);
  gl.glBegin(GL.GL_POLYGON);
  gl.glVertex3f(xPosition,yPosition - SPACING / 2,BUTTON_Z);
  gl.glVertex3f(xPosition,yPosition + ITEM_HEIGHT - SPACING / 2,BUTTON_Z);
  gl.glVertex3f(xPosition + subMenu.width - 2 * SPACING,yPosition + ITEM_HEIGHT - SPACING,BUTTON_Z);
  gl.glVertex3f(xPosition + subMenu.width - 2 * SPACING,yPosition - SPACING / 2,BUTTON_Z);
  gl.glEnd();
  gl.glPopName();
  EIconTextures iconTexture=item.getIconTexture();
  if (iconTexture != null) {
    Texture tempTexture=iconManager.getIconTexture(gl,iconTexture);
    tempTexture.enable();
    tempTexture.bind();
    TextureCoords texCoords=tempTexture.getImageTexCoords();
    gl.glColor4f(1,1,1,1);
    gl.glPushName(iPickingID);
    gl.glBegin(GL.GL_POLYGON);
    gl.glTexCoord2f(texCoords.left(),texCoords.bottom());
    gl.glVertex3f(xPosition,yPosition,TEXT_Z);
    gl.glTexCoord2f(texCoords.right(),texCoords.bottom());
    gl.glVertex3f(xPosition + ICON_SIZE,yPosition,TEXT_Z);
    gl.glTexCoord2f(texCoords.right(),texCoords.top());
    gl.glVertex3f(xPosition + ICON_SIZE,yPosition + ICON_SIZE,TEXT_Z);
    gl.glTexCoord2f(texCoords.left(),texCoords.top());
    gl.glVertex3f(xPosition,yPosition + ICON_SIZE,TEXT_Z);
    gl.glEnd();
    tempTexture.disable();
    gl.glPopName();
  }
  xPosition+=ICON_SIZE + SPACING;
  textRenderer.begin3DRendering();
  textRenderer.setColor(1,1,1,1);
  gl.glDisable(GL.GL_DEPTH_TEST);
  textRenderer.draw3D(item.getText(),xPosition,yPosition + SPACING / 2,TEXT_Z,FONT_SCALING);
  textRenderer.end3DRendering();
  xPosition+=subMenu.maxTextWidth;
  if (item.hasSubItems()) {
    Texture tempTexture=iconManager.getIconTexture(gl,EIconTextures.CM_SELECTION_RIGHT_EXTENSIBLE_BLACK);
    tempTexture.enable();
    tempTexture.bind();
    TextureCoords texCoords=tempTexture.getImageTexCoords();
    gl.glColor4f(1,1,1,1);
    gl.glPushName(iPickingID);
    gl.glBegin(GL.GL_POLYGON);
    gl.glTexCoord2f(texCoords.left(),texCoords.top());
    gl.glVertex3f(xPosition,yPosition,TEXT_Z);
    gl.glTexCoord2f(texCoords.right(),texCoords.top());
    gl.glVertex3f(xPosition + ICON_SIZE,yPosition,TEXT_Z);
    gl.glTexCoord2f(texCoords.right(),texCoords.bottom());
    gl.glVertex3f(xPosition + ICON_SIZE,yPosition + ICON_SIZE,TEXT_Z);
    gl.glTexCoord2f(texCoords.left(),texCoords.bottom());
    gl.glVertex3f(xPosition,yPosition + ICON_SIZE,TEXT_Z);
    gl.glEnd();
    tempTexture.disable();
    gl.glPopName();
    if (itemID == mouseOverElement || isSubElementSelected(item)) {
      SubMenu subSubMenu=item.getSubMenu();
      subSubMenu.xOrigin=subMenu.xOrigin + subMenu.width;
      subSubMenu.yOrigin=yPosition + ITEM_HEIGHT;
      float remainingXSpace=fRightBorder - (subMenu.xOrigin + getScaledSizeOf(gl,subMenu.width));
      float scaledWidth=getScaledSizeOf(gl,subSubMenu.width);
      if (remainingXSpace < scaledWidth)       subSubMenu.xOrigin=subMenu.xOrigin - subSubMenu.width;
      float scaledHeight=getScaledSizeOf(gl,subSubMenu.height);
      if (getScaledCoordinate(gl,subSubMenu.yOrigin,subMenu.yOrigin) - fBottomBorder < scaledHeight) {
        float distance=Math.abs(subMenu.yOrigin - fBottomBorder);
        float scaledDistance=getUnscaledSizeOf(gl,distance);
        subSubMenu.yOrigin=subMenu.yOrigin - scaledDistance + subSubMenu.height;
      }
      drawMenu(gl,item.getSubMenu(),false);
    }
  }
}

Fixed version (ground truth):
/** 
 * Renders an item in the context menu and recursively starts rendering its sub-menus if there are any
 * @param gl
 * @param subMenu
 * @param entry
 * @param xPosition
 * @param yPosition
 */
private void renderItem(GL gl,SubMenu subMenu,IContextMenuEntry entry,float xPosition,float yPosition){
  AContextMenuItem item=(AContextMenuItem)entry;
  Integer itemID=hashContextMenuItemToUniqueID.get(entry);
  if (itemID == mouseOverElement || isSubElementSelected(item))   renderHighlighting(gl,subMenu,yPosition);
  gl.glColor4f(0,0,0,0);
  int iPickingID=pickingManager.getPickingID(masterGLView.getID(),EPickingType.CONTEXT_MENU_SELECTION,itemID);
  gl.glPushName(iPickingID);
  gl.glBegin(GL.GL_POLYGON);
  gl.glVertex3f(xPosition,yPosition - SPACING / 2,BUTTON_Z * 2);
  gl.glVertex3f(xPosition,yPosition + ITEM_HEIGHT - SPACING / 2,BUTTON_Z * 2);
  gl.glVertex3f(xPosition + subMenu.width - 2 * SPACING,yPosition + ITEM_HEIGHT - SPACING,BUTTON_Z * 2);
  gl.glVertex3f(xPosition + subMenu.width - 2 * SPACING,yPosition - SPACING / 2,BUTTON_Z * 2);
  gl.glEnd();
  gl.glPopName();
  EIconTextures iconTexture=item.getIconTexture();
  if (iconTexture != null) {
    Texture tempTexture=iconManager.getIconTexture(gl,iconTexture);
    tempTexture.enable();
    tempTexture.bind();
    TextureCoords texCoords=tempTexture.getImageTexCoords();
    gl.glColor4f(1,1,1,1);
    gl.glPushName(iPickingID);
    gl.glBegin(GL.GL_POLYGON);
    gl.glTexCoord2f(texCoords.left(),texCoords.bottom());
    gl.glVertex3f(xPosition,yPosition,TEXT_Z);
    gl.glTexCoord2f(texCoords.right(),texCoords.bottom());
    gl.glVertex3f(xPosition + ICON_SIZE,yPosition,TEXT_Z);
    gl.glTexCoord2f(texCoords.right(),texCoords.top());
    gl.glVertex3f(xPosition + ICON_SIZE,yPosition + ICON_SIZE,TEXT_Z);
    gl.glTexCoord2f(texCoords.left(),texCoords.top());
    gl.glVertex3f(xPosition,yPosition + ICON_SIZE,TEXT_Z);
    gl.glEnd();
    tempTexture.disable();
    gl.glPopName();
  }
  xPosition+=ICON_SIZE + SPACING;
  textRenderer.begin3DRendering();
  textRenderer.setColor(1,1,1,1);
  gl.glDisable(GL.GL_DEPTH_TEST);
  textRenderer.draw3D(item.getText(),xPosition,yPosition + SPACING / 2,TEXT_Z,FONT_SCALING);
  textRenderer.end3DRendering();
  xPosition+=subMenu.maxTextWidth;
  if (item.hasSubItems()) {
    Texture tempTexture=iconManager.getIconTexture(gl,EIconTextures.CM_SELECTION_RIGHT_EXTENSIBLE_BLACK);
    tempTexture.enable();
    tempTexture.bind();
    TextureCoords texCoords=tempTexture.getImageTexCoords();
    gl.glColor4f(1,1,1,1);
    gl.glPushName(iPickingID);
    gl.glBegin(GL.GL_POLYGON);
    gl.glTexCoord2f(texCoords.left(),texCoords.top());
    gl.glVertex3f(xPosition,yPosition,TEXT_Z);
    gl.glTexCoord2f(texCoords.right(),texCoords.top());
    gl.glVertex3f(xPosition + ICON_SIZE,yPosition,TEXT_Z);
    gl.glTexCoord2f(texCoords.right(),texCoords.bottom());
    gl.glVertex3f(xPosition + ICON_SIZE,yPosition + ICON_SIZE,TEXT_Z);
    gl.glTexCoord2f(texCoords.left(),texCoords.bottom());
    gl.glVertex3f(xPosition,yPosition + ICON_SIZE,TEXT_Z);
    gl.glEnd();
    tempTexture.disable();
    gl.glPopName();
    if (itemID == mouseOverElement || isSubElementSelected(item)) {
      SubMenu subSubMenu=item.getSubMenu();
      subSubMenu.xOrigin=subMenu.xOrigin + subMenu.width;
      subSubMenu.yOrigin=yPosition + ITEM_HEIGHT;
      float remainingXSpace=fRightBorder - (subMenu.xOrigin + getScaledSizeOf(gl,subMenu.width));
      float scaledWidth=getScaledSizeOf(gl,subSubMenu.width);
      if (remainingXSpace < scaledWidth)       subSubMenu.xOrigin=subMenu.xOrigin - subSubMenu.width;
      float scaledHeight=getScaledSizeOf(gl,subSubMenu.height);
      if (getScaledCoordinate(gl,subSubMenu.yOrigin,subMenu.yOrigin) - fBottomBorder < scaledHeight) {
        float distance=Math.abs(subMenu.yOrigin - fBottomBorder);
        float scaledDistance=getUnscaledSizeOf(gl,distance);
        subSubMenu.yOrigin=subMenu.yOrigin - scaledDistance + subSubMenu.height;
      }
      drawMenu(gl,item.getSubMenu(),false);
    }
  }
}