Open XuanTung95 opened 1 year ago
Hi @XuanTung95 When you unplug the cable, it will be lost connection to the device. So what is your expected error message this time?
Could you cite the source for the use case you describe above? Also, please provide a complete & minimal sample code as well. Thank you!
Hi @huycozy
When you unplug the cable, it will be lost connection to the device. So what is your expected error message this time?
I unplug and then plug it again, the debug connection is lost but I can check the log in Logcat after plugging again. The problem is Isolate.spawn to start a new Isolate is not working after plugging again but does not show any error.
The code is just creating an isolate like above. You could create a button and Isolate.spawn anything to check.
I unplug and then plug it again, the debug connection is lost but I can check the log in Logcat after plugging again.
Which log did you see from Logcat? Is it same as below?
Step 2: Isolate works fine
When I run this sample code, I see this error (before unplugging the cable): Illegal argument in isolate message: object is unsendable
. There is a recent change of object kind that can be sent across isolates (see https://api.dart.dev/stable/3.0.0/dart-isolate/SendPort/send.html and https://github.com/dart-lang/sdk/commit/67683c39)
@huycozy
No, Your code is wrong. Here is full code:
import 'dart:isolate';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
_incrementCounter() async {
ReceivePort rPort = ReceivePort();
print('Call Isolate.spawn');
try {
final ret = await Isolate.spawn(_isolateEntryPoint, rPort.sendPort);
} catch (e, st) {
print('Call Isolate.spawn $e, $st');
}
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
void _isolateEntryPoint(SendPort sPort) {
print('_isolateEntryPoint start');
}
flutter 3.13.0 Android compileSdkVersion 33
After unplug/plug open logcat and click button -> Only "Call Isolate.spawn" is show, _isolateEntryPoint is not called
Thanks. I can reproduce it now. When reconnected again, there is only log flutter : Call Isolate.spawn
from logcat. But I'm not sure if this is feasible to expose error message to logcat in this case. Labeling the issue for more opinions.
FYI there was a discussion around isolates recently in discord, not sure if it is related though: https://discord.com/channels/608014603317936148/1139665451727720469
Did anyone find a solution for this? I can still replicate it.
Is there an existing issue for this?
Steps to reproduce
Expected results
Isolate.spawn should work or throw an error if not
Actual results
Step 2: Isolate works fine
Step 5: Isolate is not working, no error message is provided
Code sample
Code sample
```dart ReceivePort rPort = ReceivePort(); Isolate.spawn(_isolateEntryPoint, rPort.sendPort); void _isolateEntryPoint(SendPort sPort) { print('_isolateEntryPoint start'); } ```Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
```console [!] Flutter (Channel stable, 3.10.6, on macOS 13.0.1 22A400 darwin-x64, locale en-VN) • Flutter version 3.10.6 on channel stable at /Users/Desktop/Develop/flutter/3.10.6/flutter ! Warning: `flutter` on your path resolves to /Users/Desktop/Develop/flutter/3.3.10/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/Desktop/Develop/flutter/3.10.6/flutter. Consider adding /Users/Desktop/Develop/flutter/3.10.6/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/Desktop/Develop/flutter/3.3.10/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/Desktop/Develop/flutter/3.10.6/flutter. Consider adding /Users/Desktop/Develop/flutter/3.10.6/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision f468f3366c (5 weeks ago), 2023-07-12 15:19:05 -0700 • Engine revision cdbeda788a • Dart version 3.0.6 • DevTools version 2.23.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Android toolchain - develop for Android devices (Android SDK version 33.0.2) • Android SDK at /Users/xuantung/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. ```