title: Access violation when trying to use std::vectors created by copying elements from an array
body: <p>I'm working on a C++/CX DirectX project that is referenced in a UWP project.</p>
  
  <p>The following function is part of the C++/CX project and is called from the UWP project at the start, mainly to create some meshes.</p>
  
  <p>Everything was working fine until I changed so instead of having one <code>_trackMesh</code>, it's a <code>std::vector (_trackMeshes)</code> containing multiple meshes.
  (basically I wanted to split up the mesh, with a max number of points per mesh).</p>
  
  <p>But when I try to split the array containing all the points I get an access violation after setting the <code>localPlayerId</code> but before the end. I have no idea why.</p>
  
  <p>Any help much appreciated.</p>
  
  <p>Code:</p>
  
  <pre><code>IAsyncAction^ Track3DControl::InitializeAsync(const Array&lt;TrackPoint&gt;^ trackPoints, const Array&lt;IPlayer^&gt;^ players, int localPlayerId)
  {
      _logger-&gt;Trace(L"InitializeAsync()");
      _isInitialized = false;
  
      Utilities::Copy(trackPoints, _trackPoints);
  
      int pointCount = trackPoints-&gt;Length;
      const int maxPointCount = 5000;
      int count = (int)ceil(pointCount / (double)maxPointCount);
      _logger-&gt;Error("_trackMeshes count: " + count);
  
      _trackMeshes = ref new Array&lt;TrackMesh^&gt;(count);
      for (int i = 0; i &lt; count; i++)
      {
          _trackMeshes[i] = ref new TrackMesh(_logger, _d3dDevice, _d3dContext);
      }
  
      std::vector&lt;task&lt;void&gt;&gt; tasks;
      for (int i = 0; i &lt; count; i++)
      {
          int start = i * maxPointCount;
          int end = (i + 1)*maxPointCount;
          if (end &gt; pointCount)
          {
              end = pointCount;// -1;
          }
          std::vector&lt;TrackPoint&gt; part(end);
          for (size_t j = 0; j &lt; end-start; j++)
          {
              part[j] = _trackPoints[j+ start];
          }
          tasks.push_back(_trackMeshes[i]-&gt;InitializeAsync(&amp;part));
      }
  
      for (auto index = 0u; index &lt; static_cast&lt;unsigned int&gt;(_playerMeshes.size()); ++index)
      {
          tasks.push_back(_playerMeshes.at(index)-&gt;InitializeAsync(_playerModel.get()));
      }
  
      _localPlayerId = localPlayerId;
  
      return create_async([this, tasks]
      {
          return when_all(tasks.begin(), tasks.end()).then([this]
          {
              _isInitialized = true;
  
              _logger-&gt;Trace(L"Initialized.");
          });
      });
  }
  </code></pre>