-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segfault and valgrind errors #125
Comments
In a previous short segfault investigation, I made myself the following note, which might be helpful: With this diff diff --git a/libs/tex/poisson_blending.cpp b/libs/tex/poisson_blending.cpp
index 2bed1da..b0eed1e 100644
--- a/libs/tex/poisson_blending.cpp
+++ b/libs/tex/poisson_blending.cpp
@@ -34,12 +34,19 @@ bool valid_mask(mve::ByteImage::ConstPtr mask){
const int height = mask->height();
for (int x = 0; x < width; ++x)
- if (mask->at(x, 0, 0) == 255 || mask->at(x, height - 1, 0) == 255)
+ if (mask->at(x, 0, 0) == 255 || mask->at(x, height - 1, 0) == 255) {
+ std::cerr << "valid_mask x failed at x=" << x << ", height=" << height << ", "
+ << "mask->at(" << x << ", 0, 0) = " << (unsigned int) mask->at(x, 0, 0) << ", "
+ << "mask->at(" << x << ", " << (height - 1) << ", 0) = " << (unsigned int) mask->at(x, height - 1, 0)
+ << std::endl;
return false;
+ }
for (int y = 0; y < height; ++y)
- if (mask->at(0, y, 0) == 255 || mask->at(width - 1, y, 0) == 255)
+ if (mask->at(0, y, 0) == 255 || mask->at(width - 1, y, 0) == 255) {
+ std::cerr << "valid_mask y failed" << std::endl;
return false;
+ }
//TODO check for sane boundary conditions... I get:
|
Perhaps the mvs-texturing/libs/tex/texture_patch.cpp Line 99 in 3840a53
|
Using this script with
prints
So that 3x3 mask looks like:
And How comes it's there? |
Just for clarification, I have confirmed that also in this new case it is the
and that with assertions enabled the valgrind memory access errors disappear; so it's most likely just the assertion failure that needs to be investigated here. |
Some insight: I inserted after this line mvs-texturing/libs/tex/texture_patch.cpp Line 72 in 3840a53
assert(x != get_width() - 1 && y != get_height() - 1); which triggered as well. Again using
So we have the So
as shown above (you can see the triangle being rendered in the mask as 255s; they form a triangle). So clearly the border area is not free of Should it be? Should the triangle be rendered only as the pixel in the middle being 255? Also what ensures that the triangle |
Also interesting but probably not related to the problem: When for the This works out OK because in the check mvs-texturing/libs/tex/texture_patch.cpp Line 70 in 3840a53
But I wonder whether it's intended that |
For my reference, the place where the patches are generated is mvs-texturing/libs/tex/generate_texture_patches.cpp Lines 114 to 118 in 7126bb3
texture_patch_border = 1 is also considered (the only other place is here).
|
Until now, it was possible that a mask with a 255 in its border was generated, later failing the `valid_mask` assertions, or, if assertions are disabled by the build, segementation faults due to invalid memory accesses. See the example in the added comment for a condition where this could happen. The key insight is that if a point lay exactly on the "border" between two pixels, say between pixel N and N+1, it counted as occupying pixel N+1. So the triangle { (1,1), (1,2), (2,1) } in a 3x3 image would result in mask 64 64 64 64 255 255 64 255 64 (notice the triangle of 255s), instead of the correct mask 64 64 64 64 255 64 64 64 64 This commit fixes it by adding the condition that the last `x = width-1` and `y = height-1` must not count as `inside` the triangle. It also improves related assertions in a few places.
I've made a PR that fixes it, with full explanation, at #126. |
Thank you very much for the detailed analysis and fix! I cannot look at it at the moment but will do so within the next days. |
With the versions from #120 (comment), I sometimes (nondeterministically, see also #124) get segfault, and
valgrind
reportsInvalid read of size 4
:The text was updated successfully, but these errors were encountered: