Bugfix for global motion with 16bit internal.
diff --git a/aom_scale/generic/yv12config.c b/aom_scale/generic/yv12config.c
index 9b9242c..d3bc151 100644
--- a/aom_scale/generic/yv12config.c
+++ b/aom_scale/generic/yv12config.c
@@ -161,10 +161,11 @@
       if (ybf->y_buffer_8bit) {
         aom_free(ybf->y_buffer_8bit);
         ybf->y_buffer_8bit = NULL;
-        ybf->buf_8bit_valid = 0;
       }
     }
-
+    // y_buffer_8bit may have been allocated above, but it has not been filled
+    // in yet. So, mark it as invalid.
+    ybf->buf_8bit_valid = 0;
     ybf->corrupted = 0; /* assume not corrupted by errors */
     return 0;
   }
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index e6821cb..43ea020 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2298,6 +2298,7 @@
       cpi->use_svc ? svc->downsample_filter_phase[svc->spatial_layer_id] : 0;
 
   set_size_independent_vars(cpi);
+  cpi->source->buf_8bit_valid = 0;
   av1_setup_frame_size(cpi);
   av1_set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
 
diff --git a/av1/encoder/global_motion.c b/av1/encoder/global_motion.c
index 6c2d9ad..b6e2bc1 100644
--- a/av1/encoder/global_motion.c
+++ b/av1/encoder/global_motion.c
@@ -365,6 +365,17 @@
     }
     frm->buf_8bit_valid = 1;
   }
+#if CONFIG_DEBUG
+  else {
+    // frm->buf_8bit_valid == 1. So, double check that 'buf_8bit' is correct.
+    for (i = 0; i < frm->y_height; ++i) {
+      for (j = 0; j < frm->y_width; ++j) {
+        assert(buf_8bit[i * frm->y_stride + j] ==
+               (orig_buf[i * frm->y_stride + j] >> (bit_depth - 8)));
+      }
+    }
+  }
+#endif  // CONFIG_DEBUG
   return buf_8bit;
 }