flame-engine / flame

A Flutter based game engine.
https://flame-engine.org
MIT License
9.29k stars 913 forks source link

Flame.util.initialDimensions - Unhandled Exception: Bad state: Future already completed #153

Closed JaviBonilla closed 5 years ago

JaviBonilla commented 5 years ago

I am getting this error message only on release mode with Flutter 1.9.1, although it seems to be working fine.

E/flutter ( 4594): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Bad state: Future already completed
E/flutter ( 4594): #0      _AsyncCompleter.complete (dart:async/future_impl.dart:39)
E/flutter ( 4594): #1      Util.initialDimensions.<anonymous closure>.<anonymous closure> (package:flame/util.dart:47)
E/flutter ( 4594): #2      _rootRun (dart:async/zone.dart:1124)
E/flutter ( 4594): #3      _CustomZone.run (dart:async/zone.dart:1021)
E/flutter ( 4594): #4      _CustomZone.runGuarded (dart:async/zone.dart:923)
E/flutter ( 4594): #5      _invoke (dart:ui/hooks.dart:249)
E/flutter ( 4594): #6      _updateWindowMetrics (dart:ui/hooks.dart:63)

This is the code:

void main() async {
  final screenSize = await Flame.util.initialDimensions();
  ....
}

This does not produce the error.

void main() async {
  final screenSize = Size(360, 592);
  ....
}

flutter doctor -v [✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Linux, locale en_US.UTF-8) • Flutter version 1.9.1+hotfix.2 at /home/javi/flutter • Framework revision 2d2a1ffec9 (5 days ago), 2019-09-06 18:39:49 -0700 • Engine revision b863200c37 • Dart version 2.5.0

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) • Android SDK at /home/javi/Android/Sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-28, build-tools 28.0.3 • Java binary at: /home/javi/android-studio/jre/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) • All Android licenses accepted.

[✓] Android Studio (version 3.5) • Android Studio at /home/javi/android-studio • Flutter plugin version 39.0.3 • Dart plugin version 191.8423 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.38.0) • VS Code at /usr/share/code • Flutter extension version 3.3.0

[✓] Connected device (1 available) • Nexus 5 • 071838e613ccb133 • android-arm • Android 6.0.1 (API 23)

• No issues found!

luanpotter commented 5 years ago

Maybe you are calling initialDimensions twice? It's says future already completed, meaning someone was awaiting for the same future as you... Just a guess, though.

JaviBonilla commented 5 years ago

@luanpotter, It is strange that I am getting this error only on release mode, but I will check what you mention, thanks.

erickzanardo commented 5 years ago

@JaviBonilla can you share more of your code? So we can have a better informations to help you?

erickzanardo commented 5 years ago

Fixed on #160

JaviBonilla commented 5 years ago

@erickzanardo I am sorry I forgot to answer you here. Thank a lot for the fix!