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

Fix Buffer Corruption #19268

Merged
merged 3 commits into from
Sep 6, 2020
Merged

Conversation

cosmoderp
Copy link
Contributor

Description

Fixes files over 22 characters long in the DWIN screen for the ender3 V2. Adjust buffer for size of the DWIN screen width. Also Set of DWIN_Strings so the the string buffer is not longer than the string.

Benefits

This fixes the over 22 character file name issue that caused buffer corruption. This resolves the high speed and some of the crashes associated with this buffer corruption.

Configurations

configs.zip

Related Issues

#18790

Fixes files over 22 characters long in the DWIN screen for the ender3 V2
@AnHardt
Copy link
Contributor

AnHardt commented Sep 5, 2020

DWIN_WIDTH / 8 is the number of symbols/glyphs.
If there is any chance the text is UTF8-text the c-string may need up to 3 bytes per symbol.

@sjasonsmith
Copy link
Contributor

@AnHardt good point. I had recommended this solution because it matches the logic in the calling function, which centers the text on the screen. That didn’t account for multi-byte characters so it slipped my mind.

If not accounted for here, it will crop the string too short.
If not accounted for in the calling function, it will make the text off-center.

It should be easy to confirm that by using some translated file names.

Simply making the buffer larger might introduce issues for single-byte characters if printing strings wider than the display misbehaves.

@enigmaquip
Copy link
Contributor

The T5UIC1 doesn't handle utf8 being sent to it anyways. It'll take ascii or GB2312, it's why all the Chinese text is from a stored image file. It really needs a utf to gb2312 charmap for full language compatability

@sjasonsmith
Copy link
Contributor

If that is the case then it seems we should just ignore any concern for multi-byte characters in this PR.

@enigmaquip
Copy link
Contributor

I don't know that it'll ever need to be that large, but according to the docs the buffer can up to 254 bytes

@sjasonsmith
Copy link
Contributor

the buffer can up to 254 bytes

If we increase the size to 254 there would need to be some testing to see what happens when the string is too wide for the screen, unless you already know...

@enigmaquip
Copy link
Contributor

If we increase the size to 254 there would need to be some testing to see what happens when the string is too wide for the screen, unless you already know...

I have no problem testing if you'd like.
On a side note to that comment the DWIN_WIDTH / 8 doesn't account for that either as DWIN_Draw_String allows you to set the font size as defined in dwin.h
font6x12, font8x16, font10x20, font12x24, font14x28, font16x32, font20x40, font24x48, font28x56, font32x64

@sjasonsmith
Copy link
Contributor

The 8 should really be replaced with a named constant. It exists in DWIN.cpp. It need to move out to a header somewhere son it can be used in both files.

@enigmaquip
Copy link
Contributor

enigmaquip commented Sep 5, 2020

The screen just draws to the end of the screen and omits the rest.
I was wrong on the max size of the buffer, it'd actually be 250 because it's 254 max with the 4 buff tail bytes.
If we wanted to make the buffer only as large as as many bytes as it'd take to draw the max number of characters on screen we'd want
11 + Width / 6 (the smallest font size width) * 2 (the number of bytes for gb2312 encoded characters)

edited to add the 11 (the bytes for the string command itself [mode, colors, x,y])

Copy link
Contributor

@sjasonsmith sjasonsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will want to test this change out, but I think this captures the suggestions from @enigmaquip.

(Hopefully you can just click "accept suggestion" to make these changes)

Marlin/src/lcd/dwin/dwin_lcd.cpp Outdated Show resolved Hide resolved
Marlin/src/lcd/dwin/dwin_lcd.cpp Outdated Show resolved Hide resolved
cosmoderp and others added 2 commits September 5, 2020 21:26
After some testing, this centered the text better.

Co-authored-by: Jason Smith <[email protected]>
@cosmoderp
Copy link
Contributor Author

This last one did seem to center stuff better. Some truncation is to be expected when text is too long since you can only ever fit so much on screen.

@thinkyhead
Copy link
Member

Thanks! I was looking askance at that array yesterday but got distracted.

@thinkyhead thinkyhead merged commit 86b71b8 into MarlinFirmware:bugfix-2.0.x Sep 6, 2020
davidveg added a commit to davidveg/Marlin that referenced this pull request Sep 9, 2020
* commit 'bc7720c0cd3917f44200c0b78e1b635e4c7b6797': (483 commits)
  Minor HAL cleanup
  [cron] Bump distribution date (2020-09-09)
  Update HAL/STM32 platform to 8.0 (MarlinFirmware#18496)
  Make M600 heat up the nozzle. Reset runout on fail. (MarlinFirmware#19298)
  [cron] Bump distribution date (2020-09-08)
  TFT is neither "graphical" nor "character" (MarlinFirmware#19297)
  Sanity-check BABYSTEP_DISPLAY_TOTAL with ColorUI (MarlinFirmware#19284)
  Fix M166 Gradient Mix for DELTA (MarlinFirmware#19285)
  Separate Neopixel followup (MarlinFirmware#19287)
  Clean up LCD conditionals, DWIN
  Whitespace cleanup
  Adjust GTR PeripheralPins to avoid timer conflicts (MarlinFirmware#19183)
  STM32F1 EP with USB_COMPOSITE (MarlinFirmware#19281)
  Menu items for Separate NeoPixel (MarlinFirmware#19280)
  [cron] Bump distribution date (2020-09-07)
  Clarify disabling StallGuard for axes (MarlinFirmware#19263)
  Touch UI long filenames fixes (MarlinFirmware#19262)
  Fix Ender 3 V2 (DWIN) buffer overrun (MarlinFirmware#19268)
  Fix STM32F1 SPI device init, MKS_LCD12864 (MarlinFirmware#19271)
  Emergency Parser for STM32F1 (MarlinFirmware#19279)
  ...

# Conflicts:
#	.github/issue_template.md
#	Marlin/Configuration.h
#	Marlin/Configuration_adv.h
#	README.md
davidveg added a commit to davidveg/Marlin that referenced this pull request Sep 9, 2020
* commit 'bc7720c0cd3917f44200c0b78e1b635e4c7b6797': (483 commits)
  Minor HAL cleanup
  [cron] Bump distribution date (2020-09-09)
  Update HAL/STM32 platform to 8.0 (MarlinFirmware#18496)
  Make M600 heat up the nozzle. Reset runout on fail. (MarlinFirmware#19298)
  [cron] Bump distribution date (2020-09-08)
  TFT is neither "graphical" nor "character" (MarlinFirmware#19297)
  Sanity-check BABYSTEP_DISPLAY_TOTAL with ColorUI (MarlinFirmware#19284)
  Fix M166 Gradient Mix for DELTA (MarlinFirmware#19285)
  Separate Neopixel followup (MarlinFirmware#19287)
  Clean up LCD conditionals, DWIN
  Whitespace cleanup
  Adjust GTR PeripheralPins to avoid timer conflicts (MarlinFirmware#19183)
  STM32F1 EP with USB_COMPOSITE (MarlinFirmware#19281)
  Menu items for Separate NeoPixel (MarlinFirmware#19280)
  [cron] Bump distribution date (2020-09-07)
  Clarify disabling StallGuard for axes (MarlinFirmware#19263)
  Touch UI long filenames fixes (MarlinFirmware#19262)
  Fix Ender 3 V2 (DWIN) buffer overrun (MarlinFirmware#19268)
  Fix STM32F1 SPI device init, MKS_LCD12864 (MarlinFirmware#19271)
  Emergency Parser for STM32F1 (MarlinFirmware#19279)
  ...

# Conflicts:
#	.github/issue_template.md
#	README.md
davidveg added a commit to davidveg/Marlin that referenced this pull request Sep 9, 2020
* 2.0.x: (483 commits)
  Minor HAL cleanup
  [cron] Bump distribution date (2020-09-09)
  Update HAL/STM32 platform to 8.0 (MarlinFirmware#18496)
  Make M600 heat up the nozzle. Reset runout on fail. (MarlinFirmware#19298)
  [cron] Bump distribution date (2020-09-08)
  TFT is neither "graphical" nor "character" (MarlinFirmware#19297)
  Sanity-check BABYSTEP_DISPLAY_TOTAL with ColorUI (MarlinFirmware#19284)
  Fix M166 Gradient Mix for DELTA (MarlinFirmware#19285)
  Separate Neopixel followup (MarlinFirmware#19287)
  Clean up LCD conditionals, DWIN
  Whitespace cleanup
  Adjust GTR PeripheralPins to avoid timer conflicts (MarlinFirmware#19183)
  STM32F1 EP with USB_COMPOSITE (MarlinFirmware#19281)
  Menu items for Separate NeoPixel (MarlinFirmware#19280)
  [cron] Bump distribution date (2020-09-07)
  Clarify disabling StallGuard for axes (MarlinFirmware#19263)
  Touch UI long filenames fixes (MarlinFirmware#19262)
  Fix Ender 3 V2 (DWIN) buffer overrun (MarlinFirmware#19268)
  Fix STM32F1 SPI device init, MKS_LCD12864 (MarlinFirmware#19271)
  Emergency Parser for STM32F1 (MarlinFirmware#19279)
  ...

# Conflicts:
#	Marlin/Configuration.h
#	platformio.ini
vgadreau pushed a commit to vgadreau/Marlin that referenced this pull request Dec 9, 2020
kageurufu pushed a commit to CR30-Users/Marlin-CR30 that referenced this pull request Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants