text: [{"Owner":"digEmAll","Date":"2016-01-14T21:26:36Z","Content":"_lt_div class_eq__qt_mages_qt__gt_\n\t\t\t\n_lt_p_gt_\n\tHi All_co_\n_lt_/p_gt_\n\n_lt_p_gt_\n\tI am new to this forum so I hope I didn_t_t break any rule writing my question here...\n_lt_/p_gt_\n\n_lt_p_gt_\n\tMy problem is probably trivial but I_t_m not sure how to implement it correctly.\n_lt_/p_gt_\n\n_lt_p_gt_\n\tBasically I have a project where users can trigger some 90° box rotations (implemented as animations) by clicking on a button.\n_lt_/p_gt_\n\n_lt_p_gt_\n\tRotations work as expected_co_ but problems arise when user clicks multiple times before previous rotations have completed. In this case_co_ obviously_co_ the following rotations start while the box is in the middle of previous movements therefore the final position of the box is not a multiple of 90° with respect to the initial position.\n_lt_/p_gt_\n\n_lt_p_gt_\n\tI made a playground example to reproduce the problem_dd_ _lt_a href_eq__qt_http_dd_//babylonjs-playground.com/#1NSSHK%230_qt_ rel_eq__qt_external nofollow_qt__gt_http_dd_//babylonjs-playground.com/#1NSSHK#0_lt_/a_gt_\n_lt_/p_gt_\n\n_lt_p_gt_\n\tI think I should use the callback function of the rotation_co_ but I_t_m not sure how (I_t_m pretty new to javascript...)\n_lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n_lt_p_gt_\n\tThanks in advance\n_lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n\n\t\t\t\n\t\t_lt_/div_gt_\n\n\t\t_lt_div class_eq__qt_ipsI_qt__gt__lt_/div_gt__lt_/div_gt_"},{"Owner":"iiceman","Date":"2016-01-14T23:09:49Z","Content":"_lt_div class_eq__qt_mages_qt__gt_\n\t\t\t\n_lt_p_gt_\n\tHi there digEmAll and welcome to the forum.\n_lt_/p_gt_\n\n_lt_p_gt_\n\tHow about something like that_dd_ _lt_a href_eq__qt_http_dd_//babylonjs-playground.com/#1NSSHK%231_qt_ rel_eq__qt_external nofollow_qt__gt_http_dd_//babylonjs-playground.com/#1NSSHK#1_lt_/a_gt_\n_lt_/p_gt_\n\n_lt_p_gt_\n\tThe idea is not to add to the current rotation but to the current target rotation. This way the clicks still add up. Does it work for you like that? Alternatively you could try to prevent another click if the animation is already in progress_co_ should be easy_co_ too. Maybe something like that_dd_ _lt_a href_eq__qt_http_dd_//babylonjs-playground.com/#1NSSHK%232_qt_ rel_eq__qt_external nofollow_qt__gt_http_dd_//babylonjs-playground.com/#1NSSHK#2_lt_/a_gt_\n_lt_/p_gt_\n\n\n\t\t\t\n\t\t_lt_/div_gt_\n\n\t\t_lt_div class_eq__qt_ipsI_qt__gt__lt_/div_gt__lt_/div_gt_"},{"Owner":"digEmAll","Date":"2016-01-15T07:40:22Z","Content":"_lt_div class_eq__qt_mages_qt__gt_\n\t\t\t\n_lt_p_gt_\n\tThanks iiceman for your solutions_co_ but I don_t_t want to disable the button because user should be able to create a _qt_chain_qt_ of rotations_co_ and I can_t_t use the first solution as well because that means the second (or third_co_ forth.. ) rotation will start before the end of the previous.\n_lt_/p_gt_\n\n_lt_p_gt_\n\tProbably I oversimplified my example_co_ but basically in the real case_co_ box can rotate by 90° in different directions (around x_co_ y or z) and different rotations cannot be _qt_combined_qt__co_ but only _qt_chained_qt_.\n_lt_/p_gt_\n\n_lt_p_gt_\n\tMy quick_t_n_t_dirty solution is to use an array as rotations queue_co_ as shown here _dd_  _lt_a href_eq__qt_http_dd_//babylonjs-playground.com/#1NSSHK%233_qt_ rel_eq__qt_external nofollow_qt__gt_http_dd_//babylonjs-playground.com/#1NSSHK#3_lt_/a_gt_\n_lt_/p_gt_\n\n_lt_p_gt_\n\tbut I_t_m not expert enough in javascript to be sure this approach is safe.\n_lt_/p_gt_\n\n_lt_p_gt_\n\tFor example_co_ is there a risk for a stack overflow due to the recursion?\n_lt_/p_gt_\n\n_lt_p_gt_\n\tAre the operations _qt_atomic_qt_ enough such that I_t_m sure that nothing can happen between the status boolean change and the status boolean check ?\n_lt_/p_gt_\n\n_lt_p_gt_\n\tThanks again _lt_img alt_eq__qt__dd_)_qt_ data-emoticon_eq__qt_true_qt_ height_eq__qt_20_qt_ src_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/default_smile.png_qt_ srcset_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/smile@2x.png 2x_qt_ title_eq__qt__dd_)_qt_ width_eq__qt_20_qt__gt__lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n\n\t\t\t\n\t\t_lt_/div_gt_\n\n\t\t_lt_div class_eq__qt_ipsI_qt__gt__lt_/div_gt__lt_/div_gt_"},{"Owner":"RaananW","Date":"2016-01-15T08:21:34Z","Content":"_lt_div class_eq__qt_mages_qt__gt_\n\t\t\t\n_lt_blockquote class_eq__qt_ipsQuote_qt_ data-ipsquote_eq__qt__qt_ data-ipsquote-contentapp_eq__qt_forums_qt_ data-ipsquote-contentclass_eq__qt_forums_Topic_qt_ data-ipsquote-contentcommentid_eq__qt_112729_qt_ data-ipsquote-contentid_eq__qt_19862_qt_ data-ipsquote-contenttype_eq__qt_forums_qt_ data-ipsquote-timestamp_eq__qt_1452843622_qt_ data-ipsquote-userid_eq__qt_18362_qt_ data-ipsquote-username_eq__qt_digEmAll_qt__gt_\n\t_lt_div class_eq__qt_ipsQuote_citation_qt__gt_\n\t\t37 minutes ago_co_ digEmAll said_dd_\n\t_lt_/div_gt_\n\n\t_lt_div class_eq__qt_ipsQuote_contents_qt__gt_\n\t\t_lt_p_gt_\n\t\t\t \n\t\t_lt_/p_gt_\n\n\t\t_lt_p_gt_\n\t\t\tAre the operations _qt_atomic_qt_ enough such that I_t_m sure that nothing can happen between the status boolean change and the status boolean check ?\n\t\t_lt_/p_gt_\n\n\t\t_lt_p_gt_\n\t\t\t \n\t\t_lt_/p_gt_\n\t_lt_/div_gt_\n_lt_/blockquote_gt_\n\n_lt_p_gt_\n\tHaven_t_t checked the demo (on mobile)_co_ just wanted to comment on the last question you had - JavaScript is single threaded_co_ all operations are technically atomic. You just need to sort your code correctly _dd_-)\n_lt_/p_gt_\n\n_lt_p_gt_\n\tOh_co_ and this is totally the right place for this question. Especially with a playground already included ?\n_lt_/p_gt_\n\n\n\t\t\t\n\t\t_lt_/div_gt_\n\n\t\t_lt_div class_eq__qt_ipsI_qt__gt__lt_/div_gt__lt_/div_gt_"},{"Owner":"iiceman","Date":"2016-01-15T08:37:30Z","Content":"_lt_div class_eq__qt_mages_qt__gt_\n\t\t\t\n_lt_p_gt_\n\tI am no expert either_co_ but I am pretty sure that should work. And as far as I know using a queue is a common approach. I don_t_t believe that something can interfere between the flag change and reading the flag_co_ that happens pretty much right after another as far as I can tell. About the stack overflow_dd_ how many clicks do you plan on putting in the queue? _lt_img alt_eq__qt__dd_D_qt_ data-emoticon_eq__qt_true_qt_ height_eq__qt_20_qt_ src_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/default_biggrin.png_qt_ srcset_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/biggrin@2x.png 2x_qt_ title_eq__qt__dd_D_qt_ width_eq__qt_20_qt__gt_ \n_lt_/p_gt_\n\n_lt_p_gt_\n\tI found this on... well_co_ stackoverflow_dd_ \n_lt_/p_gt_\n\n_lt_p_gt_\n\t_lt_a href_eq__qt_http_dd_//stackoverflow.com/questions/2805172/what-are-the-js-recursion-limits-for-firefox-chrome-safari-ie-etc_qt_ rel_eq__qt_external nofollow_qt__gt_http_dd_//stackoverflow.com/questions/2805172/what-are-the-js-recursion-limits-for-firefox-chrome-safari-ie-etc_lt_/a_gt_\n_lt_/p_gt_\n\n_lt_p_gt_\n\t_lt_a href_eq__qt_http_dd_//stackoverflow.com/questions/7826992/browser-javascript-stack-size-limit_qt_ rel_eq__qt_external nofollow_qt__gt_http_dd_//stackoverflow.com/questions/7826992/browser-javascript-stack-size-limit_lt_/a_gt_\n_lt_/p_gt_\n\n_lt_p_gt_\n\tMaybe you can limit your queue to 1000 items or something like that to be on the save side? But who would be clicking a 1000 times on a rotate button? _lt_img alt_eq__qt__sm_)_qt_ data-emoticon_eq__qt_true_qt_ height_eq__qt_20_qt_ src_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/default_wink.png_qt_ srcset_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/wink@2x.png 2x_qt_ title_eq__qt__sm_)_qt_ width_eq__qt_20_qt__gt__lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n\n\t\t\t\n\t\t_lt_/div_gt_\n\n\t\t_lt_div class_eq__qt_ipsI_qt__gt__lt_/div_gt__lt_/div_gt_"},{"Owner":"digEmAll","Date":"2016-01-15T12:59:13Z","Content":"_lt_div class_eq__qt_mages_qt__gt_\n\t\t\t\n_lt_blockquote class_eq__qt_ipsQuote_qt_ data-ipsquote_eq__qt__qt_ data-ipsquote-contentapp_eq__qt_forums_qt_ data-ipsquote-contentclass_eq__qt_forums_Topic_qt_ data-ipsquote-contentcommentid_eq__qt_112740_qt_ data-ipsquote-contentid_eq__qt_19862_qt_ data-ipsquote-contenttype_eq__qt_forums_qt_ data-ipsquote-timestamp_eq__qt_1452847050_qt_ data-ipsquote-userid_eq__qt_12304_qt_ data-ipsquote-username_eq__qt_iiceman_qt__gt_\n\t_lt_div class_eq__qt_ipsQuote_citation_qt__gt_\n\t\t4 hours ago_co_ iiceman said_dd_\n\t_lt_/div_gt_\n\n\t_lt_div class_eq__qt_ipsQuote_contents_qt__gt_\n\t\t_lt_p_gt_\n\t\t\tI am no expert either_co_ but I am pretty sure that should work. And as far as I know using a queue is a common approach. I don_t_t believe that something can interfere between the flag change and reading the flag_co_ that happens pretty much right after another as far as I can tell. About the stack overflow_dd_ how many clicks do you plan on putting in the queue? _lt_img alt_eq__qt__dd_D_qt_ data-emoticon_eq__qt_true_qt_ height_eq__qt_20_qt_ src_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/default_biggrin.png_qt_ srcset_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/biggrin@2x.png 2x_qt_ title_eq__qt__dd_D_qt_ width_eq__qt_20_qt__gt_ \n\t\t_lt_/p_gt_\n\n\t\t_lt_p_gt_\n\t\t\tI found this on... well_co_ stackoverflow_dd_ \n\t\t_lt_/p_gt_\n\n\t\t_lt_p_gt_\n\t\t\t_lt_a href_eq__qt_http_dd_//stackoverflow.com/questions/2805172/what-are-the-js-recursion-limits-for-firefox-chrome-safari-ie-etc_qt_ rel_eq__qt_external nofollow_qt__gt_http_dd_//stackoverflow.com/questions/2805172/what-are-the-js-recursion-limits-for-firefox-chrome-safari-ie-etc_lt_/a_gt_\n\t\t_lt_/p_gt_\n\n\t\t_lt_p_gt_\n\t\t\t_lt_a href_eq__qt_http_dd_//stackoverflow.com/questions/7826992/browser-javascript-stack-size-limit_qt_ rel_eq__qt_external nofollow_qt__gt_http_dd_//stackoverflow.com/questions/7826992/browser-javascript-stack-size-limit_lt_/a_gt_\n\t\t_lt_/p_gt_\n\n\t\t_lt_p_gt_\n\t\t\tMaybe you can limit your queue to 1000 items or something like that to be on the save side? But who would be clicking a 1000 times on a rotate button? _lt_img alt_eq__qt__sm_)_qt_ data-emoticon_eq__qt_true_qt_ height_eq__qt_20_qt_ src_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/default_wink.png_qt_ srcset_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/wink@2x.png 2x_qt_ title_eq__qt__sm_)_qt_ width_eq__qt_20_qt__gt__lt_/p_gt_\n\n\t\t_lt_p_gt_\n\t\t\t \n\t\t_lt_/p_gt_\n\t_lt_/div_gt_\n_lt_/blockquote_gt_\n\n_lt_p_gt_\n\tThanks_co_ for the research _lt_img alt_eq__qt__dd_)_qt_ data-emoticon_eq__qt_true_qt_ height_eq__qt_20_qt_ src_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/default_smile.png_qt_ srcset_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/smile@2x.png 2x_qt_ title_eq__qt__dd_)_qt_ width_eq__qt_20_qt__gt__lt_/p_gt_\n\n_lt_p_gt_\n\tActually these _qt_rotations_qt_ might happen also programmatically_co_ so it_t_s easier to reach a greater number than user-clicked only_co_ anyway I don_t_t think I would never reach 100 times. _lt_img alt_eq__qt__dd_D_qt_ data-emoticon_eq__qt_true_qt_ height_eq__qt_20_qt_ src_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/default_biggrin.png_qt_ srcset_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/biggrin@2x.png 2x_qt_ title_eq__qt__dd_D_qt_ width_eq__qt_20_qt__gt__lt_/p_gt_\n\n_lt_p_gt_\n\tThanks to all for the help ! _lt_img alt_eq__qt__dd_)_qt_ data-emoticon_eq__qt_true_qt_ height_eq__qt_20_qt_ src_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/default_smile.png_qt_ srcset_eq__qt_http_dd_//www.html5gamedevs.com/uploads/emoticons/smile@2x.png 2x_qt_ title_eq__qt__dd_)_qt_ width_eq__qt_20_qt__gt__lt_/p_gt_\n\n_lt_p_gt_\n\t \n_lt_/p_gt_\n\n\n\t\t\t\n\t\t_lt_/div_gt_\n\n\t\t_lt_div class_eq__qt_ipsI_qt__gt__lt_/div_gt__lt_/div_gt_"}]