Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression: cannot dereference end map/set iterator on Windows #1475

Closed
2 tasks done
Skyost opened this issue Apr 17, 2023 · 4 comments · Fixed by #1480
Closed
2 tasks done

Expression: cannot dereference end map/set iterator on Windows #1475

Skyost opened this issue Apr 17, 2023 · 4 comments · Fixed by #1480
Labels
bug platform-windows Affects the windows platform reproducible Bug can be reproduced

Comments

@Skyost
Copy link
Contributor

Skyost commented Apr 17, 2023

Checklist

  • I read the troubleshooting guide before raising this issue
  • I made sure that the issue I am raising doesn't already exist

Current bug behaviour

Audio cannot be played on Windows due to a MVC++ error occuring.

Expected behaviour

Audio should play without any problem.

Steps to reproduce

  1. Clone the repository and extract the flame_audio example project.
  2. Run flutter create . in order to create the Windows project.
  3. flutter run.

Code sample

Code sample
import 'package:flame/components.dart';
import 'package:flame/extensions.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flame/palette.dart';
import 'package:flame_audio/flame_audio.dart';
import 'package:flutter/widgets.dart' hide Animation;

void main() {
  runApp(GameWidget(game: AudioGame()));
}

/// This example game showcases three possible use cases:
///
/// 1. Use the static FlameAudio class to easily fire a sfx using the default
/// configs for the button tap.
/// 2. Uses a custom AudioPool for extremely efficient audio loading and pooling
/// for tapping elsewhere.
/// 3. Uses the Bgm utility for background music.
class AudioGame extends FlameGame with TapDetector {
  static Paint black = BasicPalette.black.paint();
  static Paint gray = const PaletteEntry(Color(0xFFCCCCCC)).paint();
  static TextPaint text = TextPaint(
    style: TextStyle(color: BasicPalette.white.color),
  );

  late AudioPool pool;

  @override
  Future<void> onLoad() async {
    pool = await FlameAudio.createPool(
      'sfx/fire_2.mp3',
      minPlayers: 3,
      maxPlayers: 4,
    );
    startBgmMusic();
  }

  Rect get button => Rect.fromLTWH(20, size.y - 300, size.x - 40, 200);

  void startBgmMusic() {
    FlameAudio.bgm.initialize();
    FlameAudio.bgm.play('music/bg_music.ogg');
  }

  void fireOne() {
    FlameAudio.play('sfx/fire_1.mp3');
  }

  void fireTwo() {
    pool.start();
  }

  @override
  void render(Canvas canvas) {
    super.render(canvas);
    canvas.drawRect(size.toRect(), black);

    text.render(
      canvas,
      '(click anywhere for 1)',
      Vector2(size.x / 2, 200),
      anchor: Anchor.topCenter,
    );

    canvas.drawRect(button, gray);

    text.render(
      canvas,
      'click here for 2',
      Vector2(size.x / 2, size.y - 200),
      anchor: Anchor.bottomCenter,
    );
  }

  @override
  void onTapDown(TapDownInfo info) {
    if (button.containsPoint(info.eventPosition.game)) {
      fireTwo();
    } else {
      fireOne();
    }
  }
}

(as you can see, it's the sample project of flame_audio, which is available here).

Affected platforms

Windows

Platform details

Processor : AMD Ryzen 5 5600H with Radeon Graphics 3.30 GHz
RAM : 16,0 Go (15,3 Go usable)
Edition : Windows 11 Famille
Version : 22H2
Installed on : ‎05/‎10/‎2022
OS Build : 22621.1555
Experience : Windows Feature Experience Pack 1000.22640.1000.0

AudioPlayers Version

4.0.1

Build mode

debug

Audio Files/URLs/Sources

bg_music.ogg

Screenshots

2023-04-17_12-36

Logs

No log as it's a native error. See screenshot above.

Related issues / more information

No response

Working on PR

Why not, but I have no C++ experience.

@Skyost Skyost added the bug label Apr 17, 2023
@Gustl22
Copy link
Collaborator

Gustl22 commented Apr 19, 2023

Good catch @Skyost. The following happens: Dispose is called on bgm in FlameAudio, which should not be the case as it makes the player obsolete, should be replaced with release() (cc @spydon).

But it should also be tested and fixed in AP, as a player could call a method even after being disposed.

#1450
#1478

Further .ogg is not supported by Windows, but that was not the problem for crashing here :)

@Gustl22 Gustl22 added platform-windows Affects the windows platform reproducible Bug can be reproduced labels Apr 19, 2023
@Gustl22 Gustl22 mentioned this issue Apr 19, 2023
7 tasks
@spydon
Copy link
Member

spydon commented Apr 19, 2023

Good catch indeed, I'll fix flame_audio!

@Skyost
Copy link
Contributor Author

Skyost commented Apr 23, 2023

Good ! Can I close this one @Gustl22 ?

@Gustl22
Copy link
Collaborator

Gustl22 commented Apr 24, 2023

I'll close, when #1480 is merged ;)

Gustl22 added a commit that referenced this issue May 3, 2023
# Description

- Add `PlayerState.disposed` (closes #1450)
- Add `AudioPool.dispose()` (closes #1478)
- Dispose players in tests
- Properly handle dispose on all platforms (closes #1475)
- Fix running method calls on non UI threads causes PlatformException
(closes #1481)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug platform-windows Affects the windows platform reproducible Bug can be reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants