Repository navigation
[pigeon] C++ generator doesn't handle non-class FlutterApi parameters correctly #108682
Copy link
Copy link
Closed
flutter/packages
#3042Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Steps to Reproduce
Using the following dart code and generation invocation, it causes Flutter native to crash due to an assert related to the (what I assume) is the type id not recognized.
import 'package:pigeon/pigeon.dart';
@FlutterApi()
abstract class Native2Flutter {
void onClick(bool forward);
}flutter pub run pigeon --input native_channels/mouse_event.dart --dart_out lib/pigeon.dart --experimental_cpp_header_out windows/runner/pigeon.hpp --experimental_cpp_source_out windows/runner/pigeon.cppUsing pigeon: ^3.2.6 which resolves to 3.2.6 as of 7/30/2022
Data
The assert is in standard_codec.cc line 77. I was able to remedy the problem by modifying the generated C++ source file with the following:
void Native2Flutter::onClick(bool forward_arg, std::function<void(void)>&& callback) {
auto channel = std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
binary_messenger_, "dev.flutter.pigeon.Native2Flutter.onClick", &GetCodec());
- channel->Send(flutter::EncodableList{flutter::CustomEncodableValue(forward_arg)}, [callback](const uint8_t *reply, size_t reply_size)
+ channel->Send(flutter::EncodableList{flutter::EncodableValue(forward_arg)}, [callback](const uint8_t *reply, size_t reply_size)
{ callback(); });
}Expected results:
No native crash, event gets invoked as intended
Actual results:
Flutter doctor
[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.19044.1826], locale en-US)
• Flutter version 3.0.5 at E:\SSDUse\DevPrograms\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f1875d570e (2 weeks ago), 2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at E:\SSDUse\AppData\Android\SDK
• Platform android-31, build-tools 32.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
• All Android licenses accepted.
[√] Chrome - develop for the web
• CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.0 Preview 1.0)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Preview
• Visual Studio Community 2022 version 17.1.31903.286
• The current Visual Studio installation is a pre-release version. It may not be supported by Flutter yet.
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2021.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
[√] IntelliJ IDEA Ultimate Edition (version 2022.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2021.1.2
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
[√] VS Code (version 1.69.2)
• VS Code at C:\Users\fernr\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.22.0
[√] Connected device (4 available)
• Quest 2 (mobile) • 1WMHH8127B0362 • android-arm64 • Android 10 (API 29)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19044.1826]
• Chrome (web) • chrome • web-javascript • unknown
• Edge (web) • edge • web-javascript • Microsoft Edge 103.0.1264.37
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
I apologize in advance if I didn't provide enough details and/or a sample. I assumed the code shown above is enough to provide a useful sample.
cc @gaaclarke
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version

Activity
[-][Windows] pigeon generation not encoding bool in function argument[/-][+][Windows] pigeon generation not properly encoding bool in function argument[/+]danagbemava-nc commentedon Aug 1, 2022
Hi @Fernthedev, I'm not familiar enough with pigeon to repro this. Can you provide a complete minimal sample, preferably in a repo so that we can easily run and confirm this?
Thank you
stuartmorgan-g commentedon Aug 1, 2022
No need, this is a known issue; non-class parameters for FlutterApi are currently broken in the C++ generator. flutter/packages#2270 fixed HostApi but not FlutterApi.
Since it looks like I didn't file a tracking issue, retitling this one.
[-][Windows] pigeon generation not properly encoding bool in function argument[/-][+][pigeon] C++ generator doesn't handle non-class FlutterApi parameters correctly[/+]github-actions commentedon Mar 4, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.