Skip to content

Commit

Permalink
Fixed|libappfw|TextDrawable: Potential crash when changing text durin…
Browse files Browse the repository at this point in the history
…g wrapping

TextDrawable didn't check if a wrapping task was ongoing before
clearing a background wrapper.

Todo for later: TextDrawable needs to be rewritten with more clarity
and robustness regarding background tasks.
  • Loading branch information
skyjake committed Mar 26, 2014
1 parent 9644613 commit 066a6d9
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions doomsday/libappfw/src/textdrawable.cpp
Expand Up @@ -67,12 +67,20 @@ DENG2_PIMPL(TextDrawable)

Wrapper *frontWrap; ///< For drawing.
Wrapper *backWrap; ///< For background task.
String pendingStyledText;
bool pending;
bool needSwap;
bool needUpdate;
TaskPool tasks;
volatile duint32 validWrapId;

Instance(Public *i) : Base(i), inited(false), needSwap(false), needUpdate(false), validWrapId(0)
Instance(Public *i)
: Base(i)
, inited(false)
, pending(false)
, needSwap(false)
, needUpdate(false)
, validWrapId(0)
{
frontWrap = new Wrapper;
backWrap = new Wrapper;
Expand Down Expand Up @@ -191,6 +199,16 @@ void TextDrawable::setLineWrapWidth(int maxLineWidth)

void TextDrawable::setText(String const &styledText)
{
// If backWrap is being wrapped right now we shouldn't block, but add a pending wrap
// task instead.
if(!d->tasks.isDone())
{
// Cannot interrupt the ongoing backWrap.
d->pendingStyledText = styledText;
d->pending = true;
return;
}

d->backWrap->clear();
d->needUpdate = true;

Expand Down Expand Up @@ -231,7 +249,16 @@ bool TextDrawable::update()

bool wasNotReady = !isReady();
bool changed = GLTextComposer::update() || swapped || (isReady() && wasNotReady);
return changed && !isBeingWrapped();
bool result = changed && !isBeingWrapped();

// Begin a pending wrap?
if(!isBeingWrapped() && d->pending)
{
d->pending = false;
setText(d->pendingStyledText);
}

return result;
}

FontLineWrapping const &TextDrawable::wraps() const
Expand Down

0 comments on commit 066a6d9

Please sign in to comment.