title: Controls absurd size from SizeChanged event
body: <p>I got my video player. As long as it loads it is hidden (1 on 1 pixel size applied to object). When it is done loading it fires JavaScript functions and is resized to desired size (640 x 480px i.e.). In effect <code>SizeChanged</code> event is fired. In that event handler media element is resized to keep proper aspect ratio.</p>
  
  <p>The problem is from time to time I got absurd size like: <code>ActualWidth == 448900, ActualHeight == 286090</code>.</p>
  
  <p>Anyone was having troubles at least similar to this one? I couldn't reproduce it on my test environment so I have no idea how, when and why it does happen. Any suggestions might be helpful.</p>
  
  <p>SizeChanged handler:</p>
  
  <pre><code>private void Player_SizeChanged(object sender, SizeChangedEventArgs e)
  {
      Size pSize = e.NewSize;
      if (_controlPanel.Visibility == System.Windows.Visibility.Visible)
          pSize = new Size(e.NewSize.Width, e.NewSize.Height - _controlPanel.PanelRoot.Height);
  
      _videoPanel.OnParentSizeChanged(pSize);
  }
  </code></pre>
  
  <p>VideoPanel.OnParentSizeChanged:</p>
  
  <pre><code>public void OnParentSizeChanged(Size newSize)
  {
      //nothing to do here
      if (_lastLayoutSize != null &amp;&amp;
          _lastLayoutSize.Width == newSize.Width &amp;&amp;
          _lastLayoutSize.Height == newSize.Height)
          return;
  
      _lastLayoutSize = new Size(newSize.Width, newSize.Height);
      ApplyAspectRatio();
  }
  </code></pre>
  
  <p>VideoPanel.ApplyAspectRatio:</p>
  
  <pre><code>public void ApplyAspectRatio()
  {
      //security checks
      if (_lastLayoutSize == null)
          return;
  
      if (_mediaSource == null)
      {
          if (_imgThumbnail != null)
          {
              this.Width = _lastLayoutSize.Width;
              this.Height = _lastLayoutSize.Height;
          }
  
          return;
      }
  
      if (_mediaSource.Width == 0 || _mediaSource.Height == 0)
          return;
  
      double dScale = 1.0;
      double dSourceHeight = 1.0;
      double dSourceWidth = 1.0;
  
      lock (_msSync)
      {
          dSourceWidth = _mediaSource.Width;
          dSourceHeight = _mediaSource.Height;
  
          double dHeightRatio = 1.0;
          double dWidthRatio = 1.0;
  
          dHeightRatio = _lastLayoutSize.Height / dSourceHeight;
          dWidthRatio = _lastLayoutSize.Width / dSourceWidth;
  
          dScale = System.Math.Min(dHeightRatio, dWidthRatio);
      }
  
      double nWidth = dSourceWidth * dScale;
      double nHeight = dSourceHeight * dScale;
  
      Width = MaxWidth = MinWidth = nWidth;
      Height = MaxHeight = MinHeight = nHeight;
  
      this.InvalidateArrange();
  }
  </code></pre>
  
  <p>I removed code for logging. It was just writing some text to isolated storage. Those absurd values occures in top of that invocation chain, Player_SizeChanged method.</p>