diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index e5dae9343fcc890a8b1e771a298d9ad4d61372f9..ebf3178b38f7853bf25d0ddf18d905dea02053ce 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -571,6 +571,10 @@ static void CleanFromVideoContext(void *priv)
 
 static void ReleaseAllPictureContexts(decoder_sys_t *p_sys)
 {
+    /* No picture context if no direct rendering. */
+    if (p_sys->video.ctx == NULL)
+        return;
+
     for (size_t i = 0; i < ARRAY_SIZE(p_sys->video.apic_ctxs); ++i)
     {
         struct android_picture_ctx *apctx = &p_sys->video.apic_ctxs[i];