[DirectX] Fix vector allocation for raw data handling.

std::vector::reserve has the effect to reserve space in memory but does
not affect the result of size(), which keeps on returning 0. If size is
0, however, data() might either return null or not [1].

This CL fixes the use of reserve() in favour of resize() which
effectively allocates the memory in the vector and updates its size.
This way size() returns a value bigger than 0 and data() returns a valid
pointer.

[1] https://en.cppreference.com/w/cpp/container/vector/data

Fixed: chromium:1059764
Change-Id: Ida3dbe643710c6895f09b9da87b0075b7d7b28df
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170470
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Commit-Queue: Armando Miraglia <armax@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30836}
This commit is contained in:
Armando Miraglia 2020-03-16 13:10:26 +01:00 committed by Commit Bot
parent 9ce14e8c50
commit b52f7fb593

View File

@ -275,7 +275,7 @@ bool DxgiOutputDuplicator::DoDetectUpdatedRegion(
if (metadata_.capacity() < frame_info.TotalMetadataBufferSize) { if (metadata_.capacity() < frame_info.TotalMetadataBufferSize) {
metadata_.clear(); // Avoid data copy metadata_.clear(); // Avoid data copy
metadata_.reserve(frame_info.TotalMetadataBufferSize); metadata_.resize(frame_info.TotalMetadataBufferSize);
} }
UINT buff_size = 0; UINT buff_size = 0;