Skip to content

Windows WidgetsBinding displays getter throws exception after update from 3.35.7 to 3.38.2 after calling SetWindowPos #178982

Closed

Description

@krll-kov
Display(id: 65537, size: Size(3456.0, 2090.0), devicePixelRatio: 2.0, refreshRate: 120.0)
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: 'dart:ui/window.dart': Failed assertion: line 106 pos 12: '<optimized out>': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:67:4)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:49:5)
#2      FlutterView.display (dart:ui/window.dart:106:12)
#3      main (package:untitled/main.dart:64:64)
#4      _runMain.<anonymous closure> (dart:ui/hooks.dart:345:23)
#5      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:314:19)
#6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:12)

How to reproduce:

import 'dart:convert';
import 'dart:ffi';

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  // GOOD CALL
  print(WidgetsBinding.instance.platformDispatcher.views.first.display);

  final user32 = DynamicLibrary.open('user32.dll');
  final msvcrt = DynamicLibrary.open('msvcrt.dll');

  final malloc = msvcrt
      .lookupFunction<
        Pointer<Void> Function(IntPtr),
        Pointer<Void> Function(int)
      >('malloc');

  final findWindowA = user32
      .lookupFunction<
        Pointer<Void> Function(Pointer<Int8>, Pointer<Int8>),
        Pointer<Void> Function(Pointer<Int8>, Pointer<Int8>)
      >('FindWindowA');

  final setWindowPos = user32
      .lookupFunction<
        Int32 Function(
          Pointer<Void>,
          Pointer<Void>,
          Int32,
          Int32,
          Int32,
          Int32,
          Uint32,
        ),
        int Function(Pointer<Void>, Pointer<Void>, int, int, int, int, int)
      >('SetWindowPos');

  final classNameBytes = [...ascii.encode('FLUTTER_RUNNER_WIN32_WINDOW'), 0];
  final ptr = malloc(classNameBytes.length).cast<Int8>();

  for (var i = 0; i < classNameBytes.length; i++) {
    ptr[i] = classNameBytes[i];
  }

  final hwnd = findWindowA(ptr, nullptr.cast());

  if (hwnd.address != 0) {
    setWindowPos(
      hwnd,
      nullptr,
      0,
      0,
      100,
      200,
      // SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED
      0x0004 | 0x0010 | 0x0020,
    );
  }

  // ALREADY BAD CALL
  print(WidgetsBinding.instance.platformDispatcher.views.first.display);

  runApp(const MaterialApp(debugShowCheckedModeBanner: false, home: Test()));
}

class Test extends StatelessWidget {
  const Test({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFF0F2F5),
      body: Center(
        child: SizedBox(
          width: 1000,
          height: 600,
          child: GridView.builder(
            padding: const EdgeInsets.all(20),
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 4,
              crossAxisSpacing: 20,
              mainAxisSpacing: 20,
              childAspectRatio: 16 / 9,
            ),
            itemCount: 8,
            itemBuilder: (context, index) {
              return SizedBox(child: Text('123'));
            },
          ),
        ),
      ),
    );
  }
}

Doctor v

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.38.3, on Microsoft Windows [Version 10.0.26100.7171], locale en-US)
[√] Windows Version (Windows 11 or higher, 24H2, 2009)
[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/to/windows-android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.14.21 (November 2025))
[√] Connected device (2 available)
[√] Network resources

! Doctor found issues in 2 categories.

SetWindowPos is used to change size of app' window

Activity

  1. changed the title [-]Windows WidgetsBinding displays getter throws exception after update from 3.35.7 to 3.38.2[/-] [+]Windows WidgetsBinding displays getter throws exception after update from 3.35.7 to 3.38.2 after calling SetWindowPos[/+] on Nov 23, 2025
  2. tirth-patel-nc commented on Nov 24, 2025

    @tirth-patel-nc
    Member

    Thanks for the report. Seeing the same behaviour with latest SDK versions. WAI on 3.35.7 hence marking it as a regression.

    stable : 3.38.3
    master : 3.39.0-1.0.pre-271
    
  3. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    platform-windowsBuilding on or for Windows specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-windowsOwned by the Windows platform team
    c: crashStack traces logged to the console
    engineflutter/engine related. See also e: labels.
    c: regressionIt was better in the past than it is now
    and removed
    in triagePresently being triaged by the triage team
    on Nov 24, 2025
  4. loic-sharma commented on Nov 24, 2025

    @loic-sharma
    Member

    Thanks for the bug report with the excellent repro steps!

    cc @mattkae as this looks related to your display changes.

  5. krll-kov commented on Nov 25, 2025

    @krll-kov
    ContributorAuthor

    Will this be merged as hotfix to stable branch?

  6. github-actions commented on Dec 9, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: desktopRunning on desktopc: crashStack traces logged to the consolec: regressionIt was better in the past than it is nowengineflutter/engine related. See also e: labels.found in release: 3.38Found to occur in 3.38found in release: 3.39Found to occur in 3.39frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-windowsBuilding on or for Windows specificallyr: fixedIssue is closed as already fixed in a newer versionteam-windowsOwned by the Windows platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions