Skip to content

Commit

Permalink
Sanity/bug check for safety scan failing during encode
Browse files Browse the repository at this point in the history
Ran some tests on how common this failure mode is, and 1-2% of frames
tend to be "bad" (and thus are thrown out). We should never ever hit
this 5-in-a-row case, but it'd also be pretty brutal to infinite loop
due to a bug in the will_it_scan() function...

So, paranoia for now
  • Loading branch information
sz3 committed Nov 5, 2024
1 parent 1a77fe5 commit a038d5b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/encoder/Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ inline unsigned Encoder::encode_fountain(const std::string& filename, const std:
requiredFrames = 1;

unsigned i = 0;
unsigned consecutiveScansFailed = 0;
while (i < requiredFrames)
{
auto frame = encode_next(*fes, canvas_size);
Expand All @@ -67,8 +68,15 @@ inline unsigned Encoder::encode_fountain(const std::string& filename, const std:
// corner "anchors" and fail to extract. So:
// if frame fails the scan, skip it.
if (!Scanner::will_it_scan(*frame))
continue;
{
if (++consecutiveScansFailed < 5)
continue;

// else, we gotta make forward progress. And it's probably a bug?
std::cerr << fmt::format("generated {} bad frames in a row. This really shouldn't happen, maybe report a bug. :(", consecutiveScansFailed) << std::endl;
}

consecutiveScansFailed = 0;
if (!on_frame(*frame, i))
break;
++i;
Expand Down

0 comments on commit a038d5b

Please sign in to comment.