olikraus / u8glib

Arduino Monochrom Graphics Library for LCDs and OLEDs
https://github.com/olikraus/u8glib/wiki
Other
1.24k stars 313 forks source link

u8g_DrawBox() with h=0 corrupts display #488

Open francescolavra opened 5 years ago

francescolavra commented 5 years ago

If the u8g_DrawBox() function in csrc/u8g_rect.c is called with the h argument set to 0, it corrupts the display by drawing a box that covers the entire height of the screen. This is because the body in the while() loop in u8g_draw_box() is executed before checking the value of the h argument. This can be fixed by replacing the do {} while() construct with a simple while() loop:

while( h != 0 )
{
  u8g_draw_hline(u8g, x, y, w);
  y++;    
  h--;
}
olikraus commented 5 years ago

True, but Code size will be higher.

olikraus commented 5 years ago

Well... I can add this...

AnHardt commented 5 years ago

A box with height 0 is still a line. For that, at least one line is required. How about changing the condition to h > 0

francescolavra commented 5 years ago

A box with height 0 is still a line

Why? This wouldn't be consistent with the current implementation, where a line corresponds to a box with height 1, not 0. Also, u8g_DrawBox() doesn't draw anything when called with width 0.