diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp
index 2bff868d192f9aeae18421988a6fce0ae9cb7831..89ce790f2ddaba556c807a2000d85c3ff669dac5 100644
--- a/source/Lib/CommonLib/UnitTools.cpp
+++ b/source/Lib/CommonLib/UnitTools.cpp
@@ -4226,12 +4226,13 @@ void PU::getAffineMergeCand( const PredictionUnit &pu, AffineMergeCtx& affMrgCtx
       affMrgCtx.interDirNeighbours[cnt] = 3;
     }
     affMrgCtx.affineType[cnt] = AFFINEMODEL_4PARAM;
-    cnt++;
 
-    if ( cnt == maxNumAffineMergeCand )
+    if ( cnt == mrgCandIdx )
     {
       return;
     }
+    cnt++;
+    affMrgCtx.numValidMergeCand++;
   }
 }