• recursive requestAnimationFrame

    From Mikko@mikko.levanto@iki.fi to comp.lang.javascript on Mon Nov 9 13:22:54 2026
    From Newsgroup: comp.lang.javascript

    I'm making a game with animation. With a debugger I found that the
    function requestAnimationFrame is recursive. My animation function
    ends with the call
    requestAnimationFrame(animate);
    if there is more to animate. I put a breakpoint to the animation
    function at a point that is not executed always but only when
    the display is wrong. At the breakpoint I noticed that the call
    stack has a long list of "requestAnimationFrame" so it seems to
    be recursive.

    Is requestAnimationFrame really recursive? I'm using Safari. Is
    the function recursive on other browsers? Can it cause a stack
    full exception?

    I still havn't identified my bug but it seems to be unrelated to
    the recursiveness of requestAnimationFrame.
    --
    Mikko

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From ram@ram@zedat.fu-berlin.de (Stefan Ram) to comp.lang.javascript on Mon Nov 9 13:19:19 2026
    From Newsgroup: comp.lang.javascript

    Mikko <mikko.levanto@iki.fi> wrote or quoted:
    Is requestAnimationFrame really recursive?

    No, it's just scheduling a future execution.

    Maybe that browser is showing you the /asynchronous call stack/
    ("Async Stack Traces"), not the execution stack. This async stack
    seems to be a history of scheduling ancestry. The browser saved
    a history of who scheduled whom.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From ram@ram@zedat.fu-berlin.de (Stefan Ram) to comp.lang.javascript on Mon Nov 9 13:53:23 2026
    From Newsgroup: comp.lang.javascript

    ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
    Maybe that browser is showing you the /asynchronous call stack/
    ("Async Stack Traces"), not the execution stack. This async stack
    seems to be a history of scheduling ancestry. The browser saved
    a history of who scheduled whom.

    It's also possible that what you see /is/ the actual call stack,
    and there is some other part of the code that actually /is/
    recursive. I don't have Safari here to check this out.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Mikko@mikko.levanto@iki.fi to comp.lang.javascript on Mon Nov 9 19:12:42 2026
    From Newsgroup: comp.lang.javascript

    On 09/11/2026 15:19, Stefan Ram wrote:
    Mikko <mikko.levanto@iki.fi> wrote or quoted:
    Is requestAnimationFrame really recursive?

    No, it's just scheduling a future execution.

    Maybe that browser is showing you the /asynchronous call stack/
    ("Async Stack Traces"), not the execution stack. This async stack
    seems to be a history of scheduling ancestry. The browser saved
    a history of who scheduled whom.

    That is possible. There is an anonymous entry between every pais of requestAnimationFrame entries.
    --
    Mikko
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Mikko@mikko.levanto@iki.fi to comp.lang.javascript on Mon Nov 9 19:15:11 2026
    From Newsgroup: comp.lang.javascript

    On 09/11/2026 15:53, Stefan Ram wrote:
    ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
    Maybe that browser is showing you the /asynchronous call stack/
    ("Async Stack Traces"), not the execution stack. This async stack
    seems to be a history of scheduling ancestry. The browser saved
    a history of who scheduled whom.

    It's also possible that what you see /is/ the actual call stack,
    and there is some other part of the code that actually /is/
    recursive. I don't have Safari here to check this out.

    As my animation code calls requestAnimationFrame there is an indirect
    recursion if requestAnimationFrame is recursive. Otherwise I have no
    recursion that involves requestAnimationFrame.
    --
    Mikko
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Jon Ribbens@jon+usenet@unequivocal.eu to comp.lang.javascript on Mon Nov 9 17:32:18 2026
    From Newsgroup: comp.lang.javascript

    On 2026-11-09, Mikko <mikko.levanto@iki.fi> wrote:
    On 09/11/2026 15:53, Stefan Ram wrote:
    ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
    Maybe that browser is showing you the /asynchronous call stack/
    ("Async Stack Traces"), not the execution stack. This async stack
    seems to be a history of scheduling ancestry. The browser saved
    a history of who scheduled whom.

    It's also possible that what you see /is/ the actual call stack,
    and there is some other part of the code that actually /is/
    recursive. I don't have Safari here to check this out.

    As my animation code calls requestAnimationFrame there is an indirect recursion if requestAnimationFrame is recursive. Otherwise I have no recursion that involves requestAnimationFrame.

    I'm pretty sure requestAnimationFrame is like setTimeout - it
    always returns immediately, and the function you pass it is
    called asynchronously at a later point.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Mikko@mikko.levanto@iki.fi to comp.lang.javascript on Tue Nov 10 09:31:14 2026
    From Newsgroup: comp.lang.javascript

    On 09/11/2026 19:32, Jon Ribbens wrote:
    On 2026-11-09, Mikko <mikko.levanto@iki.fi> wrote:
    On 09/11/2026 15:53, Stefan Ram wrote:
    ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
    Maybe that browser is showing you the /asynchronous call stack/
    ("Async Stack Traces"), not the execution stack. This async stack
    seems to be a history of scheduling ancestry. The browser saved
    a history of who scheduled whom.

    It's also possible that what you see /is/ the actual call stack,
    and there is some other part of the code that actually /is/
    recursive. I don't have Safari here to check this out.

    As my animation code calls requestAnimationFrame there is an indirect
    recursion if requestAnimationFrame is recursive. Otherwise I have no
    recursion that involves requestAnimationFrame.

    I'm pretty sure requestAnimationFrame is like setTimeout - it
    always returns immediately, and the function you pass it is
    called asynchronously at a later point.

    So am I. Nothing else makes sense. But the stack shown by the debugger
    looks strange. The same happens when setTimeout is used but not when setInterval is used.
    --
    Mikko
    --- Synchronet 3.22a-Linux NewsLink 1.2