Skip to content

Hot reload's warm up frame should not call FlutterView.render #125326

@loic-sharma

Description

@loic-sharma

Problem

When the user hot reloads, the framework produces a frame immediately without waiting for the vsync using SchedulerBinding.scheduleWarmUpFrame. This warm up frame incorrectly calls FlutterView.render outside of the scope of PlatformDispatcher.onBeginFrame and PlatformDispatcher.onDrawFrame, which is not allowed as per FlutterView.render's docs.

This eventually calls into Animator::Render, which attempts to reuse the pending producer continuation. Normally the producer continuation is created by the vsync in Animator::BeginFrame. However, in the hot reload scenario we skipped waiting for a vsync, never called Animator::BeginFrame, and never created a producer continuation. As a result, the pending producer continuation is likely already committed and the scene will be dropped.

You can confirm this behavior by setting a breakpoint here and hot reloading: https://github.com/flutter/engine/blob/609e71543cb4bc996348ae316ff00a0ed252518c/shell/common/animator.cc#L157

Solution

First, we should test what breaks in google3 if the engine errors if FlutterView.render is called outside the scope of PlatformDispatcher.onBeginFrame and PlatformDispatcher.onDrawFrame.

Assuming the google3 test indicates this change is reasonable:

  1. Update hot reload's warm up frame to not call FlutterView.render. Hot reload should likely set sendFramesToEngine to false.
  2. Update the engine to error if FlutterView.render is called outside the scope of PlatformDispatcher.onBeginFrame and PlatformDispatcher.onDrawFrame

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions