70b073acfd8e6128be3c8b0fe6391e5a6a7d4bd0
galt
  Wed Jan 6 14:54:22 2016 -0800
Fixing bug where user comes in with no cookies and clicks GenomeBrowser menu link to go straight to hgTracks. I needed to call the cart function for more cases, not just the lastDbPos. I also got rid of the 2 goto statements and labels.

diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c
index 8913633..8e028f1 100644
--- src/hg/hgTracks/hgTracks.c
+++ src/hg/hgTracks/hgTracks.c
@@ -8566,96 +8566,91 @@
  * scrolling. */
 {
 //warn("top of tracksDisplay()\n"); // DEBUG REMOVE
 //warn("<a href=cartDump?hgsid=%s target=_blank>cartdump</a>", cartSessionId(cart)); // DEBUG REMOVE
 char *defaultPosition = hDefaultPos(database);
 char titleVar[256];
 char *oldPosition = cartUsualString(cart, "oldPosition", "");
 boolean findNearest = cartUsualBoolean(cart, "findNearest", FALSE);
 cartRemove(cart, "findNearest");
 //warn("findNearest = %d\n", findNearest); // DEBUG REMOVE
 
 boolean positionIsVirt = FALSE;
 position = getPositionFromCustomTracks();
 if (NULL == position)
     {
+    //warn("cartGetPosition: database=%s position=%s", database, position); // DEBUG REMOVE
+    position = cartGetPosition(cart, database, &lastDbPosCart);
     if (sameOk(cgiOptionalString("position"), "lastDbPos"))
 	{
-	position = cartGetPosition(cart, database, &lastDbPosCart);
-	//warn("cartGetPosition: database=%s position=%s", database, position); // DEBUG REMOVE
 	// DEBUG REMOVE
 	//struct dyString *encoded = newDyString(4096);
 	//cartEncodeState(lastDbPosCart, encoded);
 	//warn("restored lastDbPosCart encoded state = [%s]", encoded->string); // DEBUG REMOVE
         restoreSavedVirtPosition();
 	}
-    else
-	{
-	position = cloneString(cartUsualString(cart, "position", NULL));
-	}
     //warn("position = %s\n", position); // DEBUG REMOVE
     if (startsWith("virt:", position))
 	{
 	position = stripCommas(position); // sometimes the position string arrives with commas in it.
 	//warn("positionIsVirt=TRUE position = %s\n", position); // DEBUG REMOVE
 	positionIsVirt = TRUE;
-	goto gotVirtPos;
 	}
     }
 
 
 if (sameString(position, ""))
     {
     hUserAbort("Please go back and enter a coordinate range or a search term in the \"search term\" field.<br>For example: chr22:20100000-20200000.\n");
     }
 
+if (!positionIsVirt)
+    {
     chromName = NULL;
     winStart = 0;
     if (isGenome(position) || NULL ==
 	(hgp = findGenomePos(database, position, &chromName, &winStart, &winEnd, cart)))
 	{
 	//warn("doing weird stuff with isGenome() and findGenomePos(), add more debugging");
 	if (winStart == 0)  /* number of positions found */
 	    {
 	    freeMem(position);
 	    position = cloneString(cartUsualString(cart, "lastPosition", defaultPosition));
 	    hgp = findGenomePos(database, position, &chromName, &winStart, &winEnd,cart);
 	    if (hgp != NULL && differentString(position, defaultPosition))
 		cartSetString(cart, "position", position);
 	    }
 	}
 
     /* After position is found set up hash of matches that should
        be drawn with names highlighted for easy identification. */
     createHgFindMatchHash();
 
     /* This means that no single result was found
     I.e., multiple results may have been found and are printed out prior to this code*/
     if (NULL == chromName)
 	{
 	// In case user manually edits the browser location as described in #13009,
 	// revert the position.  If they instead choose from the list as we expect,
 	// that will set the position to their choice.
+	// lastPosition gets set in cart.c
 	char *lastPosition = cartUsualString(cart, "lastPosition", hDefaultPos(database));
 	cartSetString(cart, "position", lastPosition);
 	return;
 	}
 
-// TODO NOTE lastPosition gets set in cart.c
-
-
-gotVirtPos:
+    }
 
 virtMode = cartUsualBoolean(cart, "virtMode", FALSE);
 //warn("virtMode=%d\n", virtMode); // DEBUG REMOVE
 
 /* Figure out basic dimensions of display.  This
  * needs to be done early for the sake of the
  * zooming and dinking routines. */
 setLayoutGlobals();
 //warn("after setLayoutGlobals() fullInsideX=%d fullInsideWidth=%d tl.picWidth=%d gfxBorder=%d\n", 
     //fullInsideX, fullInsideWidth, tl.picWidth, gfxBorder); // DEBUG REMOVE
 
 virtModeType = cartUsualString(cart, "virtModeType", virtModeType);
 //warn("virtModeType=%s\n", virtModeType); // DEBUG REMOVE
 
 if (positionIsVirt && virtualSingleChrom())
@@ -8670,59 +8665,63 @@
 
 // TODO GALT do we need to add in other types that now depend on emGeneTable too? maybe singleTrans?
 if (sameString(virtModeType, "exonMostly") || sameString(virtModeType, "geneMostly")) 
     {
     setEMGeneTrack();
     if (!emGeneTable) // there is no available gene table, undo exonMostly or geneMostly
 	{
 	//warn("setEMGeneTrack unable to find default gene track");
 	virtModeType = "default";
 	cartSetString(cart, "virtModeType", virtModeType); 
 	}
     }
 
 lastVirtModeType = cartUsualString(cart, "lastVirtModeType", lastVirtModeType); 
 
-again:
+while(TRUE)
+    {
     //warn("virtModeType=%s lastVirtModeType=%s\n", virtModeType, lastVirtModeType); // DEBUG REMOVE
     if (sameString(virtModeType, "default") && !(sameString(lastVirtModeType, "default")))
 	{ // RETURNING TO DEFAULT virtModeType
 	virtModeType = "default";
 	cartSetString(cart, "virtModeType", virtModeType); 
 	findNearest = TRUE;
 	if (positionIsVirt)
 	    position = cartUsualString(cart, "nonVirtPosition", "");
 	char *nvh = cartUsualString(cart, "nonVirtHighlight", NULL);
 	if (nvh)
 	    cartSetString(cart, "highlight", nvh); 
 	//warn("leaving virtMode, going to position %s", position);  // DEBUG REMOVE
 	if (!sameString(position,""))
 	    parseNonVirtPosition(position);
 	}
 
-
     //warn("\nGALT before initRegionList chromName=%s winStart=%d winEnd=%d\n", chromName, winStart,winEnd); // DEBUG REMOVE
-if (!initRegionList())   // initialize the region list, sets virtModeExtraState
+    if (initRegionList())   // initialize the region list, sets virtModeExtraState
+	{
+	break;  
+	}
+    else
 	{ // virt mode failed, forced to return to default
 	virtModeType = "default";
 	cartSetString(cart, "virtModeType", virtModeType);
 	position = cloneString(hDefaultPos(database));
 	hgp = findGenomePos(database, position, &chromName, &winStart, &winEnd, cart);
 	cartSetString(cart, "position", position);
 	positionIsVirt=FALSE;
 	virtMode=FALSE;
-    goto again;
+	}
     }
 
 // PAD padding of exon regions is now being done inside the fetch/merge.
 //if (emPadding > 0) 
     //padVirtRegions(emPadding); // this old routine does not handle multiple chroms yet
 
 //testRegionList(); // check if it is ascending non-overlapping regions. (this is not the case with custom user-defined-regions)
 
 makeVirtChrom();
 
 //testVirtChromBinarySearch();
 
 // ajax callback to convert chrom position to virt chrom position
 if (cartVarExists(cart, "hgt.convertChromToVirtChrom")) 
     {