SKKbySSK / coast_audio

Real-Time audio processing library written in Dart.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

macOS Example : `Bad State: Messenger is not attached to an worker` error

sbesnard opened this issue · comments

Hi,

I ran into this problem on may Mac M1 running vanilla example and trying to play a sample wav.

flutter: [coast_audio/AudioResource] Disposed `AudioDeviceContext` (id: 805301168)
2024-06-06 14:09:08.846 example[88820:29401807] WARNING: Secure coding is automatically enabled for restorable state! However, not on all supported macOS versions of this application. Opt-in to secure coding explicitly by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState:.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Messenger is not attached to an worker
#0      AudioIsolateHostMessenger.request (package:coast_audio/src/isolate/audio_isolate_messenger.dart:27:7)
#1      AudioIsolate.request (package:coast_audio/src/isolate/audio_isolate.dart:106:23)
#2      PlayerIsolate.getPosition (package:example/isolates/player_isolate.dart:133:21)
#3      _PlayerTileState.build.<anonymous closure> (package:example/components/player_tile.dart:160:50)
#4      _PlayerTimerBuilderState._init.<anonymous closure> (package:example/components/player_tile.dart:267:43)
#5      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#6      _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#7      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Any idea ?

Thanks in advance

Hi @sbesnard
I'm aware that the secure coding is not the actual problem.

Instead, this line indicates the exception is coming from AudioIsolate.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Messenger is not attached to an worker.
#0      AudioIsolateHostMessenger.request (package:coast_audio/src/isolate/audio_isolate_messenger.dart:27:7)
#1      AudioIsolate.request (package:coast_audio/src/isolate/audio_isolate.dart:106:23)
#2      PlayerIsolate.getPosition (package:example/isolates/player_isolate.dart:133:21)
#3      _PlayerTileState.build.<anonymous closure> (package:example/components/player_tile.dart:160:50)
#4      _PlayerTimerBuilderState._init.<anonymous closure> (package:example/components/player_tile.dart:267:43)
#5      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#6      _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#7      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Can you attach the wav file when this problem occurs?

@SKKbySSK You're right, I changed the subject of this issue. Sorry !

I just launched VSCode in the example folder of the repo.
The issue happens when I stop the recording.
I can trace the pb to this line in player_tile.dart:

onTick: (isolate) {
   return isolate.getPosition();
   },

Which in turn calls ultimately audio_isolate_messenger.dart:

Future<TResponse?> request<TRequest, TResponse>(TRequest payload) async {
    final sendPort = _sendPort;
    if (sendPort == null) {
      throw StateError('Messenger is not attached to an worker');
    }

    final request = AudioIsolateHostRequest(payload);
    final responseFuture = message.firstWhere((r) => r is AudioIsolateWorkerResponse && r.requestId == request.id);
    sendPort.send(request);

    final AudioIsolateWorkerResponse response;
    try {
      response = await responseFuture as AudioIsolateWorkerResponse;
    } on StateError {
      return null;
    }

    switch (response) {
      case AudioIsolateWorkerSuccessResponse():
        if (response.payload is TResponse) {
          return response.payload as TResponse;
        } else {
          throw StateError('Unexpected response type: ${response.payload.runtimeType}');
        }
      case AudioIsolateWorkerFailedResponse():
        return Future.error(response.exception, response.stackTrace);
    }
  }

Thanks! I am working on another piece of code that may not have this issue.I'll keep you posted.

This issue is stale because it has been open for 30 days with no activity.

This issue was closed because it has been inactive for 7 days since being marked as stale.