ImpulseAdventure / GUIslice-Builder

Cross-platform drag & drop GUI builder for GUIslice
Other
163 stars 34 forks source link

Crash when input non-ascii chars #174

Closed DynamicLoader closed 3 years ago

DynamicLoader commented 3 years ago

Describe the bug Hi, I updated builder v0.16.b011 today,and have seen the userguide that the builder now "paint" chars instead of "display"; When I try to input a Chinese sentence "你好,世界" (means "Hello,World!") ,it crashed and hundreds of popup showed. The same text inputed in v0.14.b004,builder works well.

What's more,when I right click the property "Text",the popup "CharacterMap" described in the userguide never appear.

To Reproduce Steps to reproduce the behavior:

  1. Start builder
  2. Add a Text element on the main page
  3. Edit property "Text" and input "你好,世界"
  4. Press Enter to finish input
  5. Builder crashed !

Expected behavior When input non-ascii chars,NOT to crash, popup the CharacterMap window automically or a info window instead.

Crash log / Project files This is one of hundreds of log created by the same time. 20210713_104450.txt

Screenshots GUISlice_Builder_Error_nonAscii

Version

Pconti31 commented 3 years ago

@Lucy2003 Yes, seems I need to bullet proof this code path. However, you are miss-using the builder here.

Fonts are discussed in the closed issue QUESTION: UTF-8 Support GUI Builder #140 and Chinese example in Add fonts #146

I'm posting an example of a VLW Chinese font that works with the Builder. Take the chinese_font.zip and unzip to the GUIsliceBuilder folder and unzip and replace the GUIsliceBuilder/templates with the modified builder_fonts.json that you can use as example of how to add VLM fonts. Doing this I made a sample project, selected platform ttft_espi, created a new text field, chose font wqyMicroHei.vlw (NOTE: pasting Chinese characters before changing to Chinese font will Crash!), then pasted your text 你好,世界 which worked and character map also came up when doubled clicked on field and selected character map.

chinese_font.zip builder_fonts.zip

Now your crash, under Font property you should note its currently points to Adafruit's GFX 5x8 font. This is the font inside Adafruit_GFX/glcdfont.c file which is a 7 bit font with characters from space to 128 ascii. If you create a text field with this character set and do not enter any text but instead double click on the field you will see a blank field on screen. Now right click and a mini combobox will show up given you the choice of blanking the field or going to the character map. If you pick the character map you will notice it doesn't have any Chinese characters in it which is why you crash. You enterred 你好,世界 which is actually 16 bit unicode that java understands but when it comes time to display the builder tries to use the font you chose Builtin->5x8pt7b and crashes.

If you are wondering why no crash in earlier versions of the Builder its because it wasn't WYSIWYG and simply was using the Built in Java fonts which never looked like what would appear on your TFT display.

I have asked for UTF8 support inside GUIslice API for some time but its still on the back burner. Currently UTF8 only works on the Linux target platform because that platform supports TrueType fonts with unicode that can be output as UTF8 characters. While platform like Arduino with GFX only supports 7 bit ascii. Now there are solutions here.

TFT_eSPI library supports a package U8G2 library that gives UTF8 support but Calvin @ImpulseAdventure hasn't has any time to investigate or extend GUIslice API to use this. GUIslice does support VLW fonts in SPIFFs so I also support it in the Builder. If you have a Chinese version it will work.

TFT_eSPI now also supports VLM fonts as C arrays instead of using SPIFFS, I could modify the Builder to support that though I'm not sure if GUIslice would need mods or not. Even so, I suspect it would be a small hack.

Now if Calvin ever does support U8G2 fonts getting the Builder to do might take quite some time given how poorly its format is documented . Paul--

DynamicLoader commented 3 years ago
Hi, by following your steps I can use Chinese in builder.Thanks for detailed introduction. It is suggested that the document should be modify like below: Name Value
Text The text to display. When editing,right click this field will popup a menu,...

But in my test,ESP32 with .vlw in SPIFFS is very slow.It takes ESP32 about 3s to draw 8 characters(80Mhz SPI Bus freq). What's more,I found that XKeyPadAlpha doesn't support this at the same time.CPU 1 will panic when I click a InputText element which pre-set a string contained Chinese characters.

TFT_eSPI now also supports VLM fonts as C arrays instead of using SPIFFS, I could modify the Builder to support that though I'm not sure if GUIslice would need mods or not.

I'm pleased about this,because it will increase the draw speed.It will be better if GUISlice provide a new callback that allows users load fonts from flash (or SDCard,extern NORFlash,etc) to memory dynmaicly.

Now if Calvin ever does support U8G2 fonts getting the Builder to do might take quite some time given how poorly its format is documented.

Though U8G2 font is poorly on it's font file format,but it does save much memory.It is for MCUs which are low-memory. It's suppose to add support in GUISlice,but builder can unsupport it,just use system fonts with the same size.

Builder crashed on two cases when testing

Case 1: When deleting a base page. To Reproduce:

  1. Start builder;
  2. Add a base page;
  3. Delete the base page adde before.
  4. Crashed.

Crash report is here: CrashReport_delete_basepage.txt

Case 2: When choose a recent colors of undefined. To Reproduce:

  1. Start builder;
  2. Open color chooser dialog from where you like (Options,Property View,etc);
  3. Click on recent colors like the picture below;
  4. Crashed.

Crash_on_color

Crash report is here: CrashReport_color_chooser.txt

That's all,Thank you for help again.

Pconti31 commented 3 years ago

@Lucy2003 Once again thank you for the crash information and your general input. In the future it would help me tracking these problems if you opened new issues for each different type of crash. No need to doso now but something to keep in mind for the future.

I just noticed you posted issue inside GUIslice API for U8G2 support and closed it. I think you should reopened it so Calvin can better understand what may be needed. Also, maybe a new issue inside GUIslice Repro asking for VLM fonts in C Arrays because as you know I can't make changes to the API only the Builder. Note that the last time I talked with Calvin he had injured his shoulder and was also very busy at work so it might take a while for his answer.

You should also post a bug report to GUIslice API Repro concerning the keyboard crash using VLM fonts.

If you want to do some testing I'll see what I can do for VLM fonts in C arrays inside the builder and post a test version for you. along with any modifications to the GUIslice API needed. Paul--

DynamicLoader commented 3 years ago

Hi, sorry to hear that Calvin had injured his shoulder. I think it is no need to open a new issue to report new problems before,now I understand how important it is.I will follow your advice later on reporting bugs.

What I don't understand is what does VLM mean?Is it the same as .VLW font format?

Today I viewed some code of text drawing in GUISlice,and found the speed decrease may because load and unload smooth fonts frequently. In file /src/GUIslice_drv_tft_espi.cpp: Line 422:

    #ifdef SMOOTH_FONT
      if (pFont->eFontRefType  == GSLC_FONTREF_FNAME){
        m_disp.loadFont((const char*)pFont->pvFont);
      } else {
        m_disp.setFreeFont((const GFXfont *)pFont->pvFont);
      }
    #else
      m_disp.setFreeFont((const GFXfont *)pFont->pvFont);
    #endif

Line 456:

  #ifdef SMOOTH_FONT
    if (pFont->eFontRefType  == GSLC_FONTREF_FNAME){
      m_disp.unloadFont();
    }
  #endif

I'm glad to do some test with VLM. If you can do some changes to API and then push them to a new repo or a new branch,I'd like to test them and give a feedback.What I want most is to add a callback for VLM load,which means I can load fonts from where I like (e.g. a PSRAM).It will be better if you can also do some changes to solve load and unload font problem.

Thanks for early reply!

Pconti31 commented 3 years ago

@Lucy2003 [What I don't understand is what does VLM mean?Is it the same as .VLW font format?] Yes. [ Today I viewed some code of text drawing in GUISlice,and found the speed decrease may because load and unload smooth fonts frequently.] Hmmm, maybe so. I did a quick hack (attached in a zip file) to track current smooth font and avoid loading if already loaded. Limited testing so... Let me know if it works for you. Basically:

    #ifdef SMOOTH_FONT
      if (pFont->eFontRefType  == GSLC_FONTREF_FNAME){
        if (strcmp(m_acCurrentFont, (char*)pFont->pvFont) != 0) {
          m_disp.loadFont((const char*)pFont->pvFont);
          strcpy(m_acCurrentFont, (char*)pFont->pvFont);
        }
      } else {

GUIslice_drv_tft_espi.zip

[What I want most is to add a callback for VLM load which means I can load fonts from where I like (e.g. a PSRAM).] Sorry, but you need to ask Calvin for that. If the spiffs version I just made works for you I'll drop the ROM version for now. Also, if it works you should post the loadfont vlm speed issue to GUIslice Repro so Calvin can work on a permanent fix.

Pconti31 commented 3 years ago

@Lucy2003 Oops! I forgot to dummy out the unloadfont calls. Fix is posted here: GUIslice_drv_tft_espi.zip Paul--

DynamicLoader commented 3 years ago

@Pconti31 Ha,it works well! The refresh speed is the same as using GFX fonts.What's more,after doing this change,XKeyPadAlpha popuped and can be used normally.Thank you for help!

I'll close this issue if you comfirm.

Pconti31 commented 3 years ago

@Lucy2003 Well, that was a good catch on your part!

If you are happy then I'm happy. You can close this issue.

Now if you decide in future that you need the ROM based font.vlm enhancement just post a new issue and I'll see what I can do.

Also, don't forget to post the spiffs font.vlm performance issue to GUIslice Repository so Calvin will make a fix that won't disappear on any updates to GUIslice API. Paul--