mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
vic: Fix dimension compuation of YUV frames
Fixes out of bound memory crashes in Mario Golf
This commit is contained in:
parent
8943f2158d
commit
b7fa264749
1 changed files with 10 additions and 11 deletions
|
@ -119,28 +119,27 @@ void Vic::Execute() {
|
||||||
|
|
||||||
const std::size_t surface_width = config.surface_width_minus1 + 1;
|
const std::size_t surface_width = config.surface_width_minus1 + 1;
|
||||||
const std::size_t surface_height = config.surface_height_minus1 + 1;
|
const std::size_t surface_height = config.surface_height_minus1 + 1;
|
||||||
const std::size_t half_width = surface_width / 2;
|
const auto frame_width = std::min(surface_width, static_cast<size_t>(frame->width));
|
||||||
const std::size_t half_height = config.surface_height_minus1 / 2;
|
const auto frame_height = std::min(surface_height, static_cast<size_t>(frame->height));
|
||||||
|
const std::size_t half_width = frame_width / 2;
|
||||||
|
const std::size_t half_height = frame_height / 2;
|
||||||
const std::size_t aligned_width = (surface_width + 0xff) & ~0xff;
|
const std::size_t aligned_width = (surface_width + 0xff) & ~0xff;
|
||||||
|
|
||||||
const auto* luma_ptr = frame->data[0];
|
const auto* luma_ptr = frame->data[0];
|
||||||
const auto* chroma_b_ptr = frame->data[1];
|
const auto* chroma_b_ptr = frame->data[1];
|
||||||
const auto* chroma_r_ptr = frame->data[2];
|
const auto* chroma_r_ptr = frame->data[2];
|
||||||
const auto stride = frame->linesize[0];
|
const auto stride = static_cast<size_t>(frame->linesize[0]);
|
||||||
const auto half_stride = frame->linesize[1];
|
const auto half_stride = static_cast<size_t>(frame->linesize[1]);
|
||||||
|
|
||||||
luma_buffer.resize(aligned_width * surface_height);
|
luma_buffer.resize(aligned_width * surface_height);
|
||||||
chroma_buffer.resize(aligned_width * half_height);
|
chroma_buffer.resize(aligned_width * surface_height / 2);
|
||||||
|
|
||||||
// Populate luma buffer
|
// Populate luma buffer
|
||||||
for (std::size_t y = 0; y < surface_height - 1; ++y) {
|
for (std::size_t y = 0; y < frame_height; ++y) {
|
||||||
const std::size_t src = y * stride;
|
const std::size_t src = y * stride;
|
||||||
const std::size_t dst = y * aligned_width;
|
const std::size_t dst = y * aligned_width;
|
||||||
|
for (std::size_t x = 0; x < frame_width; ++x) {
|
||||||
const std::size_t size = surface_width;
|
luma_buffer[dst + x] = luma_ptr[src + x];
|
||||||
|
|
||||||
for (std::size_t offset = 0; offset < size; ++offset) {
|
|
||||||
luma_buffer[dst + offset] = luma_ptr[src + offset];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gpu.MemoryManager().WriteBlock(output_surface_luma_address, luma_buffer.data(),
|
gpu.MemoryManager().WriteBlock(output_surface_luma_address, luma_buffer.data(),
|
||||||
|
|
Loading…
Reference in a new issue