Repository navigation
ximgproc: stop RICInterpolator using the global rand() - #4278
Open
pctablet505 wants to merge 2 commits into
Open
pctablet505 wants to merge 2 commits into
pctablet505 wants to merge 2 commits into
Conversation
PropagateModels() took its random numbers from rand(), so a rand() call made by anything else in the process changed the flow, and its srand(0) reset the generator for the rest of the application. Use a local cv::RNG, as EdgeAwareInterpolator in the same file does.
This was referenced Nov 2, 2026
…test even on exceptions Use scope guards, so an exception from interpolate() cannot leave the thread count at 1 for later tests or destroy a running std::thread.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #4260
InterpolatorTest.RICSameResultOnAnyNumberOfThreadsfails now and then on the macOS CI jobs, also in PRs that do not touch ximgproc. The reason:PropagateModels()takes its random numbers from the C libraryrand(), which the whole process shares. This PR gives it its owncv::RNG, asEdgeAwareInterpolatorin the same file already has.Why the test is flaky
PropagateModels()callssrand(0), then draws withrand().rand()call from anywhere else in the process takes a number out of that sequence, and the flow changes.rand()call anywhere in the first 2000 draws moves the flow by exactly 1.45967 pixel.The macOS failures look like that. Each platform always fails with the same value: 1.81992 on macOS-ARM64 (job) and 0.266933 on macOS-X64 (job). Other runs in the same job pass.
I don't know what calls
rand()on macOS. On Linux I could not make the test fail with more threads, under load, with ThreadSanitizer, or with a pattern-filled heap.srand(0)also reset the generator for the rest of the application.Fix
PropagateModels()createsRNG rng(0)and passes it toHypothesisGeneration().Test
New
InterpolatorTest.RICResultDoesNotDependOnRand: the flow must not change while another thread callsrand()in a loop. It fails on 4.x and passes with this PR. The other ximgproc tests still pass, andRICReferenceAccuracystays within its limit.I tested on Linux x86-64 only, so the macOS CI jobs are the real check.
Related
#4249 and #4256 fix other
RICInterpolatorbugs in the same file. All three merge cleanly with each other.Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.