title: Weird and unpredictable crash when using libx264 cross-compiled with MinGW
body: <p>I'm working on a C++ project using Visual Studio 2010 on Windows. I'm linking dynamically against x264 which I built myself as a shared library using MinGW following the guide at</p>
  
  <p><a href="http://www.ayobamiadewole.com/Blog/Others/x264compilation.aspx" rel="nofollow">http://www.ayobamiadewole.com/Blog/Others/x264compilation.aspx</a></p>
  
  <p>The strange thing is that my x264 code is working perfectly <em>sometimes</em>. Then when I change some line of code (or even change the comments in the file!) and recompile everything crashes on the line</p>
  
  <pre><code>encoder_ = x264_encoder_open(&amp;param);
  </code></pre>
  
  <p>With the message</p>
  
  <pre><code>Access violation reading location 0x00000000
  </code></pre>
  
  <p>I'm not doing anything funky at all so it's probably not my code that is wrong but I guess there is something going wrong with the linking or maybe something is wrong with how I compiled x264.</p>
  
  <p>The full initialization code:</p>
  
  <pre><code>x264_param_t param = { 0 };
  if (x264_param_default_preset(&amp;param, "ultrafast", "zerolatency") &lt; 0) {
    throw KStreamerException("x264_param_default_preset failed");
  }
  
  param.i_threads = 1;
  param.i_width = 640;
  param.i_height = 480;
  param.i_fps_num = 10;
  param.i_fps_den = 1;
  
  encoder_ = x264_encoder_open(&amp;param); // &lt;-----
  if (encoder_ == 0) {
    throw KStreamerException("x264_encoder_open failed");
  }
  
  x264_picture_alloc(&amp;pic_, X264_CSP_I420, 640, 480);
  </code></pre>
  
  <p><strong>Edit:</strong> It turns out that it always works in Release mode and when using superfast instead of ultrafast it also works in Debug mode 100%. Could it be that the ultrafast mode is doing some crazy optimizations that the debugger doesn't like?</p>