flame icon indicating copy to clipboard operation
flame copied to clipboard

`ImageComposition` results in black image

Open spydon opened this issue 3 years ago • 1 comments

Current bug behaviour

When using the ImageComposition in Flutter 3.0.1 it results in a black image, but seemingly not in 2.10.0 (Pasha tried that).

Expected behaviour

The actual composition of the images in the resulting image object.

Steps to reproduce

class MyGame extends FlameGame {
  static const imagePath = 'profile.jpg';

  @override
  Future<void> onLoad() async {
    super.onLoad();
    final image = await images.load(imagePath);

    add(SpriteComponent.fromImage(
      image,
      position: Vector2(0, 0),
      size: Vector2(100, 100),
    )..debugMode = true);

    final compositionImage =
        await (ImageComposition()
              ..add(image, Vector2.zero()))
            .compose();

    add(SpriteComponent.fromImage(
      compositionImage,
      position: Vector2(100, 0),
      size: Vector2(100, 100),
    )..debugMode = true);
  }
}

I've tried with both jpg and png.

Flutter doctor output

[✓] Flutter (Channel stable, 3.0.1, on Arch Linux 5.18.0-arch1-1, locale en_DK.UTF-8)
    • Flutter version 3.0.1 at /home/spydon/bin/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fb57da5f94 (2 weeks ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

More environment information

  • Flame version: main
  • Platform affected: linux, web (are the ones I've tried, Windows might work according to Discord)

Log information

Enter log information in this code block

More information

spydon avatar Jun 04 '22 09:06 spydon

I believe the root cause here is the Flutter bug https://github.com/flutter/flutter/issues/103803

I verified that when running in the browser with flutter run -d chrome --web-renderer canvaskit --dart-define=BROWSER_IMAGE_DECODING_ENABLED=false --profile the problem no longer appears (i.e. the images are composited properly).

st-pasha avatar Jun 11 '22 15:06 st-pasha

It's now fixed in Flutter beta.

spydon avatar Oct 21 '22 17:10 spydon

Closing this as it has long been resolved in later Flutter versions.

wolfenrain avatar Sep 21 '23 11:09 wolfenrain