Index: branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1377)
+++ branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1378)
@@ -67,9 +67,9 @@
 {
   memset( m_apcTDecTop, NULL, sizeof(m_apcTDecTop) );
+  memset( m_apcTVideoIOYuvReconFile, NULL, sizeof(m_apcTVideoIOYuvReconFile) );
 
   for(UInt layer=0; layer < MAX_LAYERS; layer++)
   {
     m_aiPOCLastDisplay[layer]  = -MAX_INT;
-    m_apcTDecTop[layer] = &m_acTDecTop[layer];
   }
 }
@@ -106,4 +106,16 @@
       free ( m_pchReconFile[i] );
       m_pchReconFile[i] = NULL;
+    }
+
+    if( m_apcTDecTop[i] )
+    {
+      delete m_apcTDecTop[i];
+      m_apcTDecTop[i] = NULL;
+    }
+
+    if( m_apcTVideoIOYuvReconFile[i] )
+    {
+      delete m_apcTVideoIOYuvReconFile[i];
+      m_apcTVideoIOYuvReconFile[i] = NULL;
     }
   }
@@ -195,6 +207,6 @@
     streamYUV.open( m_pchBLReconFile, fstream::in | fstream::binary );
   }
-  TComList<TComPic*> *cListPic = m_acTDecTop[0].getListPic();
-  m_acTDecTop[0].setBLReconFile( &streamYUV );
+  TComList<TComPic*> *cListPic = m_apcTDecTop[0]->getListPic();
+  m_apcTDecTop[0]->setBLReconFile( &streamYUV );
   pcBLPic.setLayerId( 0 );
   cListPic->pushBack( &pcBLPic );
@@ -245,8 +257,8 @@
       else
       {
-        bNewPicture = m_acTDecTop[nalu.m_nuhLayerId].decode(nalu, m_iSkipFrame, m_aiPOCLastDisplay[nalu.m_nuhLayerId], curLayerId, bNewPOC);
+        bNewPicture = m_apcTDecTop[nalu.m_nuhLayerId]->decode(nalu, m_iSkipFrame, m_aiPOCLastDisplay[nalu.m_nuhLayerId], curLayerId, bNewPOC);
 
 #if SVC_POC
-        if( (bNewPicture && m_acTDecTop[nalu.m_nuhLayerId].getParseIdc() == 3) || (m_acTDecTop[nalu.m_nuhLayerId].getParseIdc() == 0) )
+        if( (bNewPicture && m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 3) || (m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 0) )
 #else
         if (bNewPicture)
@@ -268,5 +280,5 @@
         }
 #if SVC_POC
-        else if(m_acTDecTop[nalu.m_nuhLayerId].getParseIdc() == 1) 
+        else if(m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 1) 
         {
           bitstreamFile.clear();
@@ -284,14 +296,14 @@
 
 #if SVC_POC
-    if( ( (bNewPicture && m_acTDecTop[nalu.m_nuhLayerId].getParseIdc() == 3) || m_acTDecTop[nalu.m_nuhLayerId].getParseIdc() == 0 || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) && 
-        !m_acTDecTop[nalu.m_nuhLayerId].getFirstSliceInSequence() )
+    if( ( (bNewPicture && m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 3) || m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 0 || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) && 
+        !m_apcTDecTop[nalu.m_nuhLayerId]->getFirstSliceInSequence() )
 #else
     if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS) &&
-        !m_acTDecTop[nalu.m_nuhLayerId].getFirstSliceInSequence() )
+        !m_apcTDecTop[nalu.m_nuhLayerId]->getFirstSliceInSequence() )
 #endif
     {
       if (!loopFiltered[curLayerId] || bitstreamFile)
       {
-        m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic);
+        m_apcTDecTop[curLayerId]->executeLoopFilters(poc, pcListPic);
       }
       loopFiltered[curLayerId] = (nalu.m_nalUnitType == NAL_UNIT_EOS);
@@ -299,15 +311,15 @@
       if (nalu.m_nalUnitType == NAL_UNIT_EOS)
       {
-        m_acTDecTop[nalu.m_nuhLayerId].setFirstSliceInSequence(true);
+        m_apcTDecTop[nalu.m_nuhLayerId]->setFirstSliceInSequence(true);
       }
     }
     else if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) &&
-              m_acTDecTop[nalu.m_nuhLayerId].getFirstSliceInSequence () ) 
-    {
-      m_acTDecTop[nalu.m_nuhLayerId].setFirstSliceInPicture (true);
+              m_apcTDecTop[nalu.m_nuhLayerId]->getFirstSliceInSequence () ) 
+    {
+      m_apcTDecTop[nalu.m_nuhLayerId]->setFirstSliceInPicture (true);
     }
 
 #if SVC_POC
-    if( bNewPicture && m_acTDecTop[nalu.m_nuhLayerId].getParseIdc() == 0 )
+    if( bNewPicture && m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 0 )
     {
       outputAllPictures( nalu.m_nuhLayerId, true );
@@ -327,5 +339,5 @@
           }
         }
-        m_acTVideoIOYuvReconFile[curLayerId].open( m_pchReconFile[curLayerId], true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
+        m_apcTVideoIOYuvReconFile[curLayerId]->open( m_pchReconFile[curLayerId], true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
 
         openedReconFile[curLayerId] = true;
@@ -334,5 +346,5 @@
       Bool outputPicturesFlag = true;  
 
-      if( m_acTDecTop[nalu.m_nuhLayerId].getNoOutputPriorPicsFlag() )
+      if( m_apcTDecTop[nalu.m_nuhLayerId]->getNoOutputPriorPicsFlag() )
       {
         outputPicturesFlag = false;
@@ -345,5 +357,5 @@
 
 #if SVC_POC
-      if( bNewPicture && m_acTDecTop[nalu.m_nuhLayerId].getParseIdc() != 0 )
+      if( bNewPicture && m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() != 0 )
       // New picture, slice header parsed but picture not decoded
 #else
@@ -397,10 +409,10 @@
   for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
   {
-    xFlushOutput( m_acTDecTop[layer].getListPic(), layer );
+    xFlushOutput( m_apcTDecTop[layer]->getListPic(), layer );
   }
 #endif
   // delete buffers
 #if AVC_BASE
-  UInt layerIdxmin = m_acTDecTop[0].getBLReconFile()->is_open() ? 1 : 0;
+  UInt layerIdxmin = m_apcTDecTop[0]->getBLReconFile()->is_open() ? 1 : 0;
 
   if( streamYUV.is_open() )
@@ -418,5 +430,5 @@
 #endif
   {
-    m_acTDecTop[layer].deletePicBuffer();
+    m_apcTDecTop[layer]->deletePicBuffer();
   }
 
@@ -607,11 +619,14 @@
 #endif
   {
+    m_apcTDecTop[layer] = new TDecTop;
+    m_apcTVideoIOYuvReconFile[layer] = new TVideoIOYuv;
+
     // set layer ID
-    m_acTDecTop[layer].setLayerId                      ( layer );
+    m_apcTDecTop[layer]->setLayerId                      ( layer );
 
     // create decoder class
-    m_acTDecTop[layer].create();
-
-    m_acTDecTop[layer].setLayerDec(m_apcTDecTop);
+    m_apcTDecTop[layer]->create();
+
+    m_apcTDecTop[layer]->setLayerDec(m_apcTDecTop);
   }
 #else
@@ -635,9 +650,9 @@
     if ( m_pchReconFile[layer] )
     {
-      m_acTVideoIOYuvReconFile[layer].close();
+      m_apcTVideoIOYuvReconFile[layer]->close();
     }
 
     // destroy decoder class
-    m_acTDecTop[layer].destroy();
+    m_apcTDecTop[layer]->destroy();
   }
 #else
@@ -662,17 +677,17 @@
 #endif
   {
-    m_acTDecTop[layer].init();
-    m_acTDecTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+    m_apcTDecTop[layer]->init();
+    m_apcTDecTop[layer]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
 #if CONFORMANCE_BITSTREAM_MODE
-    m_acTDecTop[layer].setNumLayer( MAX_LAYERS );
-#else
-    m_acTDecTop[layer].setNumLayer( m_tgtLayerId + 1 );
-#endif
-    m_acTDecTop[layer].setCommonDecoderParams( &m_commonDecoderParams );
+    m_apcTDecTop[layer]->setNumLayer( MAX_LAYERS );
+#else
+    m_apcTDecTop[layer]->setNumLayer( m_tgtLayerId + 1 );
+#endif
+    m_apcTDecTop[layer]->setCommonDecoderParams( &m_commonDecoderParams );
   }
 #if CONFORMANCE_BITSTREAM_MODE
   for(UInt layer = 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++)
   {
-    m_acTDecTop[layer].setConfModeFlag( m_confModeFlag );
+    m_apcTDecTop[layer]->setConfModeFlag( m_confModeFlag );
   }
 #endif
@@ -799,5 +814,5 @@
             Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
 
-            m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+            m_apcTVideoIOYuvReconFile[layerId]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
               m_outputColourSpaceConvert,
               conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
@@ -894,5 +909,5 @@
           Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
 
-          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(), m_outputColourSpaceConvert,
+          m_apcTVideoIOYuvReconFile[layerId]->write( pcPic->getPicYuvRec(), m_outputColourSpaceConvert,
             conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
             conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
@@ -1018,5 +1033,5 @@
           Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
 
-          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), m_outputColourSpaceConvert,
+          m_apcTVideoIOYuvReconFile[layerId]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), m_outputColourSpaceConvert,
             conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
             conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
@@ -1096,5 +1111,5 @@
           Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
 
-          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+          m_apcTVideoIOYuvReconFile[layerId]->write( pcPic->getPicYuvRec(),
                                                    m_outputColourSpaceConvert,
                                                    conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
@@ -1232,5 +1247,5 @@
 
     TComPicYuv* pPicCYuvRec = pic->getPicYuvRec();
-    m_acTVideoIOYuvReconFile[layerId].write( pPicCYuvRec, m_outputColourSpaceConvert,
+    m_apcTVideoIOYuvReconFile[layerId]->write( pPicCYuvRec, m_outputColourSpaceConvert,
       conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
       conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
@@ -1362,6 +1377,6 @@
 Void TAppDecTop::markAllPicturesAsErased(Int layerIdx)
 {
-  TComList<TComPic*>::iterator  iterPic = m_acTDecTop[layerIdx].getListPic()->begin();
-  Int iSize = Int( m_acTDecTop[layerIdx].getListPic()->size() );
+  TComList<TComPic*>::iterator  iterPic = m_apcTDecTop[layerIdx]->getListPic()->begin();
+  Int iSize = Int( m_apcTDecTop[layerIdx]->getListPic()->size() );
   
   for (Int i = 0; i < iSize; i++ )
@@ -1374,5 +1389,5 @@
 
       // pcPic is statically created for the external (AVC) base layer, no need to delete it
-      if( !m_acTDecTop[layerIdx].getParameterSetManager()->getActiveVPS()->getNonHEVCBaseLayerFlag() || layerIdx )
+      if( !m_apcTDecTop[layerIdx]->getParameterSetManager()->getActiveVPS()->getNonHEVCBaseLayerFlag() || layerIdx )
       {
         delete pcPic;
@@ -1382,5 +1397,5 @@
   }
 
-  m_acTDecTop[layerIdx].getListPic()->clear();
+  m_apcTDecTop[layerIdx]->getListPic()->clear();
 }
 
@@ -1467,5 +1482,5 @@
       Int picPosition = (Int)std::distance( listOfPocsInEachLayer[layerId].begin(), it );
       Int j;
-      for(j = 0, iterPic = m_acTDecTop[layerId].getListPic()->begin(); j < listOfPocsPositionInEachLayer[layerId][picPosition]; j++) // Picture to be output
+      for(j = 0, iterPic = m_apcTDecTop[layerId]->getListPic()->begin(); j < listOfPocsPositionInEachLayer[layerId][picPosition]; j++) // Picture to be output
       {
         iterPic++;
@@ -1513,5 +1528,5 @@
       Int layerId = dpbStatus.m_targetDecLayerIdList[dpbLayerCtr];
       // Output all picutres "decoded" in that layer that have POC less than the current picture
-      std::vector<TComPic> *layerBuffer = (m_acTDecTop->getLayerDec(layerId))->getConfListPic();
+      std::vector<TComPic> *layerBuffer = m_apcTDecTop[layerId]->getConfListPic();
       // Write all pictures to the file.
       if( this->getDecodedYuvLayerRefresh(layerId) )
@@ -1520,6 +1535,6 @@
         strcpy(tempFileName, this->getDecodedYuvLayerFileName( layerId ).c_str());
 
-        const TComVPS *vps = m_acTDecTop->getLayerDec(layerId)->getParameterSetManager()->getActiveVPS();
-        const TComSPS *sps = m_acTDecTop->getLayerDec(layerId)->getParameterSetManager()->getActiveSPS();
+        const TComVPS *vps = m_apcTDecTop[layerId]->getParameterSetManager()->getActiveVPS();
+        const TComSPS *sps = m_apcTDecTop[layerId]->getParameterSetManager()->getActiveSPS();
         const BitDepths &bitDpeths = vps->getBitDepths(sps, layerId);
         Int bitDepth[] = {bitDpeths.recon[CHANNEL_TYPE_LUMA], bitDpeths.recon[CHANNEL_TYPE_CHROMA]};
@@ -1576,5 +1591,5 @@
     TComList<TComPic*>::iterator iterPic;
     Int j;
-    for(j = 0, iterPic = m_acTDecTop[0].getListPic()->begin(); j < listOfPocsPositionInEachLayer[0][0]; j++) // Picture to be output
+    for(j = 0, iterPic = m_apcTDecTop[0]->getListPic()->begin(); j < listOfPocsPositionInEachLayer[0][0]; j++) // Picture to be output
     {
       iterPic++;
@@ -1600,5 +1615,5 @@
     for( Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++ )
     {
-      if( m_acTDecTop[i].getListPic()->empty() )
+      if( m_apcTDecTop[i]->getListPic()->empty() )
       {
         assert( listOfPocsInEachLayer[i].size() == 0 );
@@ -1616,5 +1631,5 @@
 
         // Picture to be output
-        for( j = 0, iterPic = m_acTDecTop[i].getListPic()->begin(); j < listOfPocsPositionInEachLayer[i][picPosition]; j++ )
+        for( j = 0, iterPic = m_apcTDecTop[i]->getListPic()->begin(); j < listOfPocsPositionInEachLayer[i][picPosition]; j++ )
         {
           iterPic++;
@@ -1651,5 +1666,5 @@
   for( Int layerIdx = 0; layerIdx < MAX_VPS_LAYER_IDX_PLUS1; layerIdx++ )
   {
-    TComList <TComPic*> *pcListPic = m_acTDecTop[layerIdx].getListPic();
+    TComList <TComPic*> *pcListPic = m_apcTDecTop[layerIdx]->getListPic();
     TComList<TComPic*>::iterator iterPic = pcListPic->begin();
     while ( iterPic != pcListPic->end() )
@@ -1703,5 +1718,5 @@
   for( Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++ )
   {
-    if( m_acTDecTop[i].getListPic()->empty() )
+    if( m_apcTDecTop[i]->getListPic()->empty() )
     {
       continue;
@@ -1710,7 +1725,7 @@
     // To check # AUs that have at least one picture not output,
     // For each layer, populate listOfPOcs if not already present
-    TComList<TComPic*>::iterator iterPic = m_acTDecTop[i].getListPic()->begin();
+    TComList<TComPic*>::iterator iterPic = m_apcTDecTop[i]->getListPic()->begin();
     Int picPositionInList = 0;
-    while (iterPic != m_acTDecTop[i].getListPic()->end())
+    while (iterPic != m_apcTDecTop[i]->getListPic()->end())
     {
       TComPic* pic = *(iterPic);
Index: branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.h	(revision 1377)
+++ branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.h	(revision 1378)
@@ -64,7 +64,6 @@
   // class interface
 #if SVC_EXTENSION
-  TDecTop                         m_acTDecTop [MAX_LAYERS];                             ///< decoder class [WARNING] suppose to use MAX_NUM_LAYER_IDS but decoder crashes, pending for further investigation
-  TDecTop*                        m_apcTDecTop [MAX_NUM_LAYER_IDS];                     ///< decoder point class 
-  TVideoIOYuv                     m_acTVideoIOYuvReconFile [MAX_NUM_LAYER_IDS];         ///< reconstruction YUV class
+  TDecTop*                        m_apcTDecTop[MAX_NUM_LAYER_IDS];                     ///< decoder point class 
+  TVideoIOYuv*                    m_apcTVideoIOYuvReconFile[MAX_NUM_LAYER_IDS];        ///< reconstruction YUV class
 #else
   TDecTop                         m_cTDecTop;                     ///< decoder class
