diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 7d24df261e09a4fa58ff9bce84002aeca92919d6..e7186c847ac4630faee57130a5400de4fafa97f4 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -3384,8 +3384,11 @@ static int decode_slice_header(H264Context *h, H264Context *h0)
             h->list_count = 2;
         else
             h->list_count = 1;
-    } else
+    } else {
         h->list_count = 0;
+        h->ref_count[0] = h->ref_count[1] = 0;
+    }
+
 
     max_refs = h->picture_structure == PICT_FRAME ? 16 : 32;