Fix: Compositor: Crash in Movie Distortion node with extreme distortions
While testing some distortion options, I noticed that the Movie Distortion node
would crash when used with e.g. (0.0, 0.0, 0.5) as the lens parameters.
This appears to be caused by 00ee917fd. Turns out that even though the input was
512x384, the extended size ended up being around 600000x500000, which obviously
caused some issues.
Therefore, this patch a) clamps the margin to be at most as wide as the input
(so 9x the pixels in the worst case) and b) fixes the indexing calculations to
not overflow the int32 values in case the input is legitimately huge.
Pull Request: https://projects.blender.org/blender/blender/pulls/137440
This commit is contained in:
@@ -73,10 +73,16 @@ DistortionGrid::DistortionGrid(
|
||||
&bottom_delta,
|
||||
&top_delta);
|
||||
|
||||
/* Clamp deltas to avoid excessive memory requirements in case of extreme distortion. */
|
||||
right_delta = std::clamp(right_delta, 0, size.x);
|
||||
left_delta = std::clamp(left_delta, 0, size.x);
|
||||
bottom_delta = std::clamp(bottom_delta, 0, size.y);
|
||||
top_delta = std::clamp(top_delta, 0, size.y);
|
||||
|
||||
/* Extend the size by the deltas of the bounds. */
|
||||
const int2 extended_size = size + int2(right_delta + left_delta, bottom_delta + top_delta);
|
||||
|
||||
distortion_grid_ = Array<float2>(extended_size.x * extended_size.y);
|
||||
distortion_grid_ = Array<float2>(int64_t(extended_size.x) * extended_size.y);
|
||||
parallel_for(extended_size, [&](const int2 texel) {
|
||||
/* The tracking distortion functions expect the coordinates to be in the space of the image
|
||||
* where the tracking camera was calibrated. So we first remap the coordinates into that space,
|
||||
@@ -98,7 +104,8 @@ DistortionGrid::DistortionGrid(
|
||||
/* Note that we should remap the coordinates back into the original size by dividing by the
|
||||
* calibration size and multiplying by the size, however, we skip the latter to store the
|
||||
* coordinates in normalized form, since this is what the shader expects. */
|
||||
distortion_grid_[texel.y * extended_size.x + texel.x] = coordinates / float2(calibration_size);
|
||||
distortion_grid_[texel.y * int64_t(extended_size.x) + texel.x] = coordinates /
|
||||
float2(calibration_size);
|
||||
});
|
||||
|
||||
BKE_tracking_distortion_free(distortion);
|
||||
|
||||
Reference in New Issue
Block a user