🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.javascript
7 messages
7 total messages Started by Mikko Mon, 09 Nov 2026 11:22
recursive requestAnimationFrame
#23
Author: Mikko
Date: Mon, 09 Nov 2026 11:22
20 lines
1862 bytes
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
Re: recursive requestAnimationFrame
#24
Author: Stefan Ram
Date: Mon, 09 Nov 2026 13:19
11 lines
1843 bytes
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.

Re: recursive requestAnimationFrame
#25
Author: Stefan Ram
Date: Mon, 09 Nov 2026 13:53
11 lines
1987 bytes
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.

Re: recursive requestAnimationFrame
#26
Author: Mikko
Date: Mon, 09 Nov 2026 17:12
16 lines
1801 bytes
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
Re: recursive requestAnimationFrame
#27
Author: Mikko
Date: Mon, 09 Nov 2026 17:15
17 lines
2033 bytes
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
Re: recursive requestAnimationFrame
#28
Author: Jon Ribbens
Date: Mon, 09 Nov 2026 17:32
19 lines
2203 bytes
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.
Re: recursive requestAnimationFrame
#29
Author: Mikko
Date: Tue, 10 Nov 2026 07:31
27 lines
2593 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads