-
Notifications
You must be signed in to change notification settings - Fork 269
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
Infinite loop when adding multi_cell twice #389
Comments
Wow, this is a very annoying bug 😢 |
I opened #390 to fix this |
Now your example would raise the following error:
Note that you probably want to use pdf.multi_cell(w=0, h=5, txt='test', new_x=XPos.LEFT)
pdf.multi_cell(w=0, h=5, txt='test', new_x=XPos.LEFT) |
Makes you wonder about the wisdom of defaulting @Lucas-C, Have you checked what happens if |
Good catch, I'm going to test that |
I have found another case where an infinite loop can still occur: def test_multi_cell_with_limited_horizontal_space(tmp_path): # issue #389
pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", "", 10)
pdf.multi_cell(w=pdf.epw - 2 * pdf.c_margin - 1, h=5, txt="test")
assert pdf.x == pdf.l_margin + pdf.epw - 2 * pdf.c_margin - 1
pdf.multi_cell(w=0, h=5, txt="test")
assert_pdf_equal(pdf, HERE / "multi_cell_with_limited_horizontal_space.pdf", tmp_path, generate=True) I think we should raise an error in My instinct would be to simply add a dummy boolean state attribute to this class... |
@Lucas-C, I only modified that code a bit, it was really written by @oleksii-shyman. The approach of checking for repeated lines with no content sounds about right. Unfortunately, it gets a little more convoluted now that we need to handle the problem deeper down in the call chain... |
Thank you for your answer @gmischler I submitted #392 to fix this |
When creating a simple pdf page and calling multi_cell twice in a row an infinite loop occurs.
Minimal code
I've traced the error to this piece of code in fpdf.py line 2860
where the resulting maximum_allowed_emwidth becomes negative. This is the result of self.x being almost equal to self.w
Environment
fpdf2
2.5.2 -> bug also present on masterThe text was updated successfully, but these errors were encountered: