From 4807ea628e49161dd7d65f3cd0f678d45ddb6b39 Mon Sep 17 00:00:00 2001
From: Hendry <hendry197@gmail.com>
Date: Thu, 5 Mar 2020 07:17:05 +0100
Subject: [PATCH] Fix Ticket #922: Decoding crash

---
 source/Lib/EncoderLib/EncLib.cpp | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp
index 13dec156d..69a2daa92 100644
--- a/source/Lib/EncoderLib/EncLib.cpp
+++ b/source/Lib/EncoderLib/EncLib.cpp
@@ -1484,11 +1484,6 @@ void EncLib::xInitSPS( SPS& sps, VPS& vps )
   sps.getSpsRangeExtension().setPersistentRiceAdaptationEnabledFlag(m_persistentRiceAdaptationEnabledFlag);
   sps.getSpsRangeExtension().setCabacBypassAlignmentEnabledFlag(m_cabacBypassAlignmentEnabledFlag);
 
-  if( m_intraPeriod < 0 )
-  {
-    sps.setRPL1CopyFromRPL0Flag( true );
-  }
-
 #if JVET_Q0119_CLEANUPS
   sps.setSubPicInfoPresentFlag(m_subPicInfoPresentFlag);
   if (m_subPicInfoPresentFlag)
@@ -2137,6 +2132,26 @@ void EncLib::xInitRPL(SPS &sps, bool isFieldCoding)
     }
   }
 
+  bool isRpl1CopiedFromRpl0 = true;
+  for( int i = 0; isRpl1CopiedFromRpl0 && i < numRPLCandidates; i++)
+  {
+    if( sps.getRPLList0()->getReferencePictureList(i)->getNumRefEntries() == sps.getRPLList1()->getReferencePictureList(i)->getNumRefEntries() )
+    {
+      for( int j = 0; isRpl1CopiedFromRpl0 && j < sps.getRPLList0()->getReferencePictureList(i)->getNumRefEntries(); j++ )
+      {
+        if( sps.getRPLList0()->getReferencePictureList(i)->getRefPicIdentifier(j) != sps.getRPLList1()->getReferencePictureList(i)->getRefPicIdentifier(j) )
+        {
+          isRpl1CopiedFromRpl0 = false;
+        }
+      }
+    }
+    else
+    {
+      isRpl1CopiedFromRpl0 = false;
+    }
+  }
+  sps.setRPL1CopyFromRPL0Flag(isRpl1CopiedFromRpl0);
+
   //Check if all delta POC of STRP in each RPL has the same sign
   //Check RPLL0 first
   const RPLList* rplList0 = sps.getRPLList0();
-- 
GitLab