Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 907)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 908)
@@ -1780,5 +1780,9 @@
 #if OUTPUT_LAYER_SETS_CONFIG
     // Simplifying the code in the #else section
+#if FIX_LAYER_ID_INIT
+    assert( scanStringToArray( cfg_highestLayerIdx[addLayerSet], m_numHighestLayerIdx[addLayerSet], "HighestLayerIdx", m_highestLayerIdx[addLayerSet] ) );
+#else
     assert( scanStringToArray( cfg_layerSetLayerIdList[addLayerSet], m_numLayerInIdList[addLayerSet], "NumLayerInIdList",  m_highestLayerIdx[addLayerSet] ) );
+#endif
 #else
     if (m_numHighestLayerIdx[addLayerSet] > 0)
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 907)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 908)
@@ -1458,8 +1458,18 @@
   }
 #endif
+#if FIX_LAYER_ID_INIT
+  // The Layer ID List variables should be derived here.
+#if DERIVE_LAYER_ID_LIST_VARIABLES
+  vps->deriveLayerIdListVariables();
+#endif
+#endif
 #if Q0078_ADD_LAYER_SETS
   vps->setPredictedLayerIds();
   vps->setTreePartitionLayerIdList();
+#if FIX_LAYER_ID_INIT
+  vps->deriveLayerIdListVariablesForAddLayerSets();
+#else
   vps->setLayerIdIncludedFlagsForAddLayerSets();
+#endif
 #endif
 #endif
@@ -1519,7 +1529,9 @@
 #endif
  #if VPS_DPB_SIZE_TABLE
+#if !FIX_LAYER_ID_INIT  // must be derived earlier to not delete additional layer sets
   // The Layer ID List variables can be derived here.  
 #if DERIVE_LAYER_ID_LIST_VARIABLES
   vps->deriveLayerIdListVariables();
+#endif
 #endif
 #if RESOLUTION_BASED_DPB
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 907)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 908)
@@ -2670,9 +2670,17 @@
   // For layer 0
   m_numLayerInIdList.push_back(1);
+#if FIX_LAYER_ID_INIT
+  m_layerSetLayerIdList.resize(m_vpsNumLayerSetsMinus1 + 1);
+#else
   m_layerSetLayerIdList.resize(m_numLayerSets);
+#endif
   m_layerSetLayerIdList[0].push_back(0);
   
   // For other layers
+#if FIX_LAYER_ID_INIT
+  for (Int i = 1; i <= m_vpsNumLayerSetsMinus1; i++)
+#else
   for( Int i = 1; i < m_numLayerSets; i++ )
+#endif
   {
     for( Int m = 0; m <= m_maxLayerId; m++)
@@ -2853,4 +2861,25 @@
 }
 
+#if FIX_LAYER_ID_INIT
+void TComVPS::deriveLayerIdListVariablesForAddLayerSets()
+{
+  m_layerSetLayerIdList.resize(m_vpsNumLayerSetsMinus1 + 1 + m_numAddLayerSets);
+
+  for (UInt i = 0; i < m_numAddLayerSets; i++)
+  {
+    Int layerNum = 0;
+    Int lsIdx = m_vpsNumLayerSetsMinus1 + 1 + i;
+    for (Int treeIdx = 1; treeIdx < m_numIndependentLayers; treeIdx++)
+    {
+      for (Int layerCnt = 0; layerCnt < m_highestLayerIdxPlus1[i][treeIdx]; layerCnt++)
+      {
+        m_layerSetLayerIdList[lsIdx].push_back(m_treePartitionLayerIdList[treeIdx][layerCnt]);
+        layerNum++;
+      }
+    }
+    m_numLayerInIdList.push_back(layerNum);
+  }
+}
+#else
 void TComVPS::setLayerIdIncludedFlagsForAddLayerSets()
 {
@@ -2878,4 +2907,5 @@
   }
 }
+#endif
 
 #endif
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 907)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 908)
@@ -989,5 +989,9 @@
 #endif
 #if Q0078_ADD_LAYER_SETS
+#if FIX_LAYER_ID_INIT
+  void    deriveLayerIdListVariablesForAddLayerSets();
+#else
   void    setLayerIdIncludedFlagsForAddLayerSets();
+#endif
   UInt    getVpsNumLayerSetsMinus1()                                             { return m_vpsNumLayerSetsMinus1; }
   Void    setVpsNumLayerSetsMinus1(UInt x)                                       { m_vpsNumLayerSetsMinus1 = x; }
Index: /branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h	(revision 907)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h	(revision 908)
@@ -186,4 +186,5 @@
 
 #define DERIVE_LAYER_ID_LIST_VARIABLES   1      ///< Derived variables based on the variables in VPS - for use in syntax table parsing
+#define FIX_LAYER_ID_INIT                1
 
 #define AVC_BASE                         1      ///< YUV BL reading for AVC base SVC
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 907)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 908)
@@ -1526,5 +1526,9 @@
     }
     vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
+#if FIX_LAYER_ID_INIT
+    vps->deriveLayerIdListVariablesForAddLayerSets();
+#else
     vps->setLayerIdIncludedFlagsForAddLayerSets();
+#endif
   }
 #endif
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 907)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 908)
@@ -588,5 +588,9 @@
 {
 #if R0042_PROFILE_INDICATION
+#if FIX_LAYER_ID_INIT
+  Bool bMultiLayerExtSpsFlag = (pcSPS->getLayerId() != 0 && pcSPS->getNumDirectRefLayers() != 0);
+#else
   Bool bMultiLayerExtSpsFlag = (pcSPS->getNumDirectRefLayers() != 0 ) ; 
+#endif
 #endif
 #if ENC_DEC_TRACE  
@@ -1003,7 +1007,9 @@
     }
   }
+#if !FIX_LAYER_ID_INIT  // It was still called because NECESSARY_FLAG does not exist and is by default "false"
 #if !NECESSARY_FLAG   // Already called once in TAppEncTop.cpp
 #if DERIVE_LAYER_ID_LIST_VARIABLES
   pcVPS->deriveLayerIdListVariables();
+#endif
 #endif
 #endif
