 +  assert(_this->hidden->w == _this->hidden->ow);
 +  assert(_this->hidden->h == _this->hidden->oh);
 +
-+  SDL_LockMutex(_this->hidden->image_data_mutex);
-+
++  SDL_LockMutex(_this->hidden->flush_mutex);
++
++  if (_this->hidden->flush_pending)
++  // If we are flushing, wait.
++  // TODO(eugenis): this blocks the game thread. Should we just drop the frame
++  // instead, or store it in some kind of a side buffer?
++  while (_this->hidden->flush_pending)
++    SDL_CondWait(_this->hidden->flush_cond, _this->hidden->flush_mutex);
++
++  // data_ready may be true here if the previous frame is not flushed yet.
++  // No problem, just drop it.
 +  SDL_memcpy(_this->hidden->image_data->data(), _this->hidden->buffer,
 +      _this->hidden->w * _this->hidden->h * _this->hidden->bpp / 8);
 +
-+  SDL_UnlockMutex(_this->hidden->image_data_mutex);
++  _this->hidden->data_ready = true;
++
++  SDL_UnlockMutex(_this->hidden->flush_mutex);
 +}
 +
 +static void NACL_UpdateRects(_THIS, int numrects, SDL_Rect *rects) {

 #endif
diff --git SDL-1.2.14/src/audio/nacl/SDL_naclaudio.cc SDL-1.2.14/src/audio/nacl/SDL_naclaudio.cc
new file mode 100644
index 0000000..ed1e499
--- /dev/null
+++ SDL-1.2.14/src/audio/nacl/SDL_naclaudio.cc
@@ -0,0 +1,133 @@

+
+  /* Determine the screen depth (use default 8-bit depth) */
+  /* we change this during the SDL_SetVideoMode implementation... */
+  vformat->BitsPerPixel = 32;
+  vformat->BytesPerPixel = 4;
+
+  _this->info.current_w = gNaclVideoWidth;
+  _this->info.current_h = gNaclVideoHeight;
+
+  /* We're done! */
+  return(0);
