melonjs/melonJS — pull request #346 by hansmi (2014-01-06 02:14:42+00:00)
Title: Fix race condition with "me.game.repaint"

This patch fixes an issue where “me.game.repaint” would not have the
desired effect, that is repainting changes made to objects.

“repaint” sets an internal “isDirty” variable, which is used and unset
by “me.game.draw”. Once per frame, as controlled by “me.sys.fps”,
“me.ScreenObject.onUpdateFrame” calls “me.game.update” which may also
set “isDirty”. “onUpdateFrame” then calls “draw” every time, which will
update the canvas and also unset the variable.

Now if “repaint” is called at the wrong time, e.g. in an event handler,
“isDirty” is set and then unset by “draw” again before it's ever used
for actually updating the screen (a race condition of sorts).
Consequently, updates made to objects, e.g. visibility, won't be shown
until something else causes the screen to be updated.

With this patch an additional variable notes a requested repaint and is
only cleared once the world and viewport have been updated. This ensures
that calling “repaint” works anytime.