Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Crash when caching glyph when IOS Keyboard is Up

This thread is locked; no one can reply to it. rss feed Print
Crash when caching glyph when IOS Keyboard is Up
jmasterx
Member #11,410
October 2009

The other thread is messed up and should be deleted.

In any case, I realized my problem was thread related, so I created an event and passed it to my thread and now it is rock solid.

Thomas Fjellstrom
Member #476
June 2000
avatar

You can edit it, and remove the html &entity or unicode thing that broke it.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

jmasterx
Member #11,410
October 2009

I tried editing it, but the edit page loads all messed up such that I cannot edit it.

SiegeLord
Member #7,827
October 2006
avatar

Were you drawing from two separate threads? I'm not sure how well that'll work.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

jmasterx
Member #11,410
October 2009

Yes, but it was not my intention.

What was happening is, I was appending the letter from the virtual keyboard to my textbox, but doing so from the application main thread (not my c++ thread), that's the thread Objective-C called my callback from.

This in itself is not harmful. The harm comes from the fact that, altering my textbox's text causes a textChanged event which causes the textbox to update its text width. The text width request causes allegro to cache glyphs it does not have which causes 'drawing'. So very indirectly, I was drawing from another thread.

Thomas Fjellstrom
Member #476
June 2000
avatar

OOsh. I wonder if we can do anything about only allowing the glyph caching to happen on the thread it was created from? Or trigger an internal event that asks the origin thread to update? Hmmm. probably not.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

jmasterx
Member #11,410
October 2009

Could something like this be done:

-Check if we are on the origin thread:
if we are not, then ask the origin thread to cache glyphs and lock the calling thread, when the origin thread is in an al_wait_for_event, instead of sending the cache request to the user, cache the glyphs, then unlock the calling thread and let it continue.

That's quite complicated but I think it could work in theory, assuming the origin thread itself is not locked waiting for the calling thread to unlock it.

The other problem this glyph caching causes, specifically on mobile devices is, a user cannot safely call al_get_text_width in their logic() function. This is because, when you get a ALLEGRO_EVENT_HALT_DRAWING, if you attempt any kind of gles calls, your app is immediately terminated. Therefore, even if you don't call your render() function, you are still screwed if your logic polls the text width and a glyph needs to be cached.

Thomas Fjellstrom
Member #476
June 2000
avatar

I think it's a bit much of a complication to ask the main thread to do things like that. Allegro doesn't take over the user's thread, so we'd have to have some kind of al_update_allegro function that needs to be called.. or hook into al_wait_for_event. In the end it might just be better to not cache/draw when not in the thread that created the display/owns the font. And possibly try to flag the glyph cache to cache those glyphs the next time it's run.

But really, your code should NOT be calling any drawing functions, at all when halted, or when not in the rendering thread. So maybe, al_get_text_width should not do what it does? One small workaround for your own work might be to request allegro to cache all the glyphs you normally use upfront (not a perfect solution :( ).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

jmasterx
Member #11,410
October 2009

What I do right now is I put the keys in an array on the calling thread, and the origin thread just reads this array in my logic(). When drawing is halted, I just omit calling logic() altogether. This seems to work for me.

Thomas Fjellstrom
Member #476
June 2000
avatar

I wonder if allegro's api could use something like: void al_run_on_display_thread(ALLEGRO_DISPLAY *dpy, void (*handler)(ALLEGRO_DISPLAY *dpy, void *p));

Question is, how we'd handle that, since allegro doesn't take over the thread. Could either hook into the wait for or get event functions, or have a ALLEGRO_RUN_CALLBACK event type that gets sent to the event queue attached to the display.

It would really just be a convenience thing, that the user can handle themselves by adding their own custom event to handle things like that. That said, I used it a lot when working on iOS (via performSelectorOn*Thread or dispatch_*) and Android (via Handlers, Activity.runOnUiThread or View.post*).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

jmasterx
Member #11,410
October 2009

I had not thought of trying to do the append operation on the origin thread, I'll have to give that a try.

Go to: