Index: src/hg/hgTables/compositeTrack.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTables/compositeTrack.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -b -B -U 4 -r1.17 -r1.18
--- src/hg/hgTables/compositeTrack.c	20 May 2009 20:59:55 -0000	1.17
+++ src/hg/hgTables/compositeTrack.c	4 Jan 2010 19:12:21 -0000	1.18
@@ -148,12 +148,12 @@
 printf("Base-pair-wise union (OR) of %s and other selected subtracks<P>\n",
        curTable);
 }
 
+
 void doSubtrackMergeMore(struct sqlConnection *conn)
 /* Respond to subtrack merge create/edit button */
 {
-struct trackDb *primary = subTdbFind(curTrack,curTable);
 char *dbTable = getDbTable(database, curTable);
 
 htmlOpen("Merge subtracks of %s (%s)",
 	 curTrack->tableName, curTrack->longLabel);
@@ -168,8 +168,9 @@
 hPrintf("<H3>Select a subset of subtracks to merge:</H3>\n");
 hCompositeUi(database, cart, curTrack, curTable, hgtaDoSubtrackMergePage, "mainForm");
 
 hPrintf("<H3>Select a merge operation:</H3>\n");
+struct trackDb *primary = subTdbFind(curTrack,curTable);
 if (isWiggle(database, curTable) || isBedGraph(curTable) || isBigWig(curTable))
     showWiggleMergeOptions(primary->longLabel);
 else
     showBedMergeOptions();
@@ -240,10 +241,12 @@
        curTable);
     else
 	errAbort("describeSubtrackMerge: unrecognized op %s", op);
     }
-for (tdb=curTrack->subtracks;  tdb != NULL;  tdb = tdb->next)
+struct slRef *tdbRef, *tdbRefList = trackDbListGetRefsToDescendantLeaves(curTrack->subtracks);
+for (tdbRef = tdbRefList; tdbRef != NULL; tdbRef = tdbRef->next)
     {
+    tdb = tdbRef->val;
     if (!sameString(tdb->tableName, curTable) &&
 	isSubtrackMerged(tdb->tableName) &&
 	sameString(tdb->type, primary->type))
 	{

