Skip to content
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

wrapping error in graphics.printf #267

Open
ericabxy opened this issue Jan 23, 2025 · 1 comment
Open

wrapping error in graphics.printf #267

ericabxy opened this issue Jan 23, 2025 · 1 comment

Comments

@ericabxy
Copy link

ericabxy commented Jan 23, 2025

There is apparently an off-by-one error in function "love.graphics.printf". In my test case I draw two boxes of 8x8 characters intended to wrap at 64px (eight characters wide). The box on the left is drawn with a "limit" parameter of 64, and the box on the right is drawn with a "limit" parameter of 63.

Image
Image

With LÖVE, the characters in the left box are allowed to exactly fill the 64px limit before wrapping, while of course in the right box the eighth character would exceed 63px and thus wraps instead.

With Lutro, the characters in the left box fill the 64px limit and one more character is allowed to be printed before wrapping. The box on the right is allowed to print the eighth character, exceeding the 63px limit. Both diverge from expected LÖVE API behavior.

Printf wrapping was apparently implemented to fix issue #77.

printfwrap.zip

@ericabxy
Copy link
Author

ericabxy commented Jan 24, 2025

I had some time and took a deeper look into the painter pipeline. "pntr_print" checks whether the next character position exceeds the "limit" parameter on line 453. Tried changing the operator to ">=" (patch file attached). This causes Lutro to print the left box correctly, but still diverge from LÖVE behavior with the right box. The current procedure seems prone to overprinting the wrap limit.

In a different patch, I carefully moved the wrap limit check before the call to pntr_draw and duplicated the expression "srect.width + font->extraspacing". This appears to solve the issue and match behavior with LÖVE, but the repeated code is a concern and I can guess at some unforseen problems (is there an edge case where drect falls out of sync with the procedure because it wraps early? Should extraspacing not be included in the early wrap check? Should the wrap check still occur after pntr_draw but make a best guess whether the next character's width would exceed the wrap limit?).

greater_than_or_equal.zip
preemptive_wrap_check.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant