ofxUI icon indicating copy to clipboard operation
ofxUI copied to clipboard

using addTextArea >> SIGABRT 'std::length_error' japanese

Open carlesgutierrez opened this issue 11 years ago • 9 comments

Hello, this error (not always ) happens while adding text ( Japanese characters ) with ofxUITextArea. Text data came from twitter. I'm trying to solve it, but still no way.

This is my code adding textArea:

myText = myText +"BLABLA"; cout << "TEXT to add=" << myText << endl; //gui->addWidgetDown( new ofxUITextArea("TEXT", myText, textsizeH, textsizeW, 0, 0, OFX_UI_FONT_SMALL ),OFX_UI_ALIGN_RIGHT, false); gui->addTextArea("TEXT", myText, OFX_UI_FONT_SMALL); cout << "Added TEXT text" << endl;

This is the terminal output where it's visible that text in the error moment

Added USER text TEXT to add=@mononoke_cat ですよねー><がんばりたい!最速でないと私死ぬます!;;BLABLA terminate called after throwing an instance of 'std::length_error' what(): basic_string::_S_create

carlesgutierrez avatar Jan 30 '14 15:01 carlesgutierrez

so is this an issue with the String or Text Renderer?

rezaali avatar Feb 02 '14 00:02 rezaali

This is here:

At: if(!reAdd) addWidget(widget); From: addWidgetPosition(widget, widgetPosition, widgetAlign); <

You reproduce it just adding this line code to a canvas:

string japanText = "世界で一番安心できる場所に、寂しさと虚しさを放り込んだら、空虚を喰らって色が生まれた";
gui->addTextArea("TEXT", japanText, OFX_UI_FONT_SMALL);

<

carlesgutierrez avatar Feb 02 '14 19:02 carlesgutierrez

I'm working with ofxUIScrollableCanvas class, trying generate a new class called ofxUIScrollableSliderCanvas to incorporate scroll bar functions to the canvas. Then by adding some texts (without specify width size or even specifying it) then here it's not able to set it into the canvas. How I should manage to protect text size in that class? Also I'm not sure about witch amount of size should be protected to avoid this string error size. Because I do not understand where it this really producing that error... Could depend this in the way to set textAreas in small canvas?

carlesgutierrez avatar Feb 04 '14 12:02 carlesgutierrez

Setting big canvas let me to add Japanese text with ofxFTGL font, then because don't need to check any more lines to format it's visible. So the error became when formatTextString() function tries to set following data for a small size area.

RT @japanill: \xe6\x96\xb0\xe5\xae\xbf\xe8\xa1\x8c\xe3\x81\xa3\xe3\x81\x9f\xe3\x81\xae\xe3\x81\xab\xe3\x83\x87\xe3\x82\xa3\xe3\x82\xb9\xe3\x82\xaf\xe3\x83\xa6\xe3\x83\x8b\xe3\x82\xaa\xe3\x83\xb3\xe6\x98\xad\xe5\x92\x8c\xe6\xad\x8c\xe8\xac\xa1\xe9\xa4\xa8\xe8\xa1\x8c\xe3\x81\x8f\xe3\x81\xae\xe5\xbf\x98\xe3\x82\x8c\xe3\x81\x9f\xe3\x80\x9c\xe3\x80\x82 (data from window expression watcher) < How should I should modify formatTextString() to accept following data? Thanks

carlesgutierrez avatar Feb 05 '14 00:02 carlesgutierrez

so I think this is a bigger issue that has to do with OF's true type font renderer, which doesn't supports Unicode...so I am working on a branch feature-swappableFontRenderer based off of @obviousjim fork of ofxUI a while ago... I am going to use ofxFTGL as the swappable font renderer since its api looks very similar to OF's true type renderer...

Side note tho, I have this philosophy of using the right tool for the job, so I would highly suggest looking into UIKit and Cocoa, Apple has been at it a lot longer than I have...

rezaali avatar Feb 10 '14 04:02 rezaali

ofxUI all the way!

Sent from my toaster

On 4 Feb 2014, at 12:59, carles [email protected] wrote:

I'm working with ofxUIScrollableCanvas class, trying generate a new class called ofxUIScrollableSliderCanvas to incorporate scroll bar functions to the canvas. Then by adding some texts (without specify width size or event specifying it but small one) then here it's not able to set into the canvas. How I should manage to protect text size in that class? Also I'm not sure about witch amount of size should be protected to avoid this string error size. Because I do not understand where it this really producing that error... Could depend this in the way to set textAreas in small canvas?

— Reply to this email directly or view it on GitHub.

sheridanis avatar Feb 10 '14 09:02 sheridanis

Yeah, ofxFTGL and the EasyCanvas font for the textArea solve this issue. We are finishing those changes in my fork. I hope to have a clean version of this soon. Cheers

carlesgutierrez avatar Feb 10 '14 20:02 carlesgutierrez

Just because we want to show japanese characters doesn't mean we should have to switch to UIKit :)

This is a super simple problem of double byte characters. What happens when you truncate a double-byte character in half you get some weird number that goes outside the glyph map, therefor crashing the font renderer when it draws. When you are truncating words that are too long, just make sure you always leave an even number of letters and it wont' crash.

On Mon, Feb 10, 2014 at 2:40 PM, carles [email protected] wrote:

Yeah, ofxFTGL and the EasyCanvas font for the textArea solves that issue. We are finishing this changes in my fork. I hope to have a clean version of this soon. Cheers

— Reply to this email directly or view it on GitHubhttps://github.com/rezaali/ofxUI/issues/172#issuecomment-34679628 .

  • James

obviousjim avatar Feb 10 '14 20:02 obviousjim

Well but FTGL addon rocks ;) Before I tried my own :

wstring and mbstowcs() to check sizes and then truncate manually by where spaces and "special characters" were, but there are many wierd ones and not was allways working for me.

UI addon also it's quite fast for change it, so why not.

carlesgutierrez avatar Feb 10 '14 23:02 carlesgutierrez