Skip to content

fix(flutter): SIGSEGV crash on macOS — missing fields in Dart FFI bindings - #3186

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
ayoubamine:fix/flutter-ffi-offline-struct-mismatch
Feb 14, 2026
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
ayoubamine:fix/flutter-ffi-offline-struct-mismatch

Conversation

@ayoubamine

@ayoubamine ayoubamine commented Feb 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Flutter Dart FFI structs are missing fields that exist in the C API, causing a crash (SIGSEGV) when creating an OfflineRecognizer on macOS.

Missing fields

SherpaOnnxOfflineWhisperModelConfig:

  • enableTokenTimestamps
  • enableSegmentTimestamps

SherpaOnnxOfflineFunAsrNanoModelConfig:

  • language
  • itn
  • hotwords

Changes

  • sherpa_onnx_bindings.dart — added missing FFI struct fields to match c-api.h
  • offline_recognizer.dart — added Dart config properties, convertConfig() pass-through, and freeConfig() cleanup

Crash

EXC_BAD_ACCESS (SIGSEGV) at 0x0000000100000000
libsherpa-onnx-c-api.dylib GetOfflineRecognizerConfig + 798
libsherpa-onnx-c-api.dylib SherpaOnnxCreateOfflineRecognizer + 32

macOS 15.7.3 / Flutter 3.38.5 / sherpa_onnx 1.12.24

Summary by CodeRabbit

  • New Features
    • Added configuration options for offline FunAsrNano model: language selection, inverse text normalization (ITN), and hotwords support.
    • Added timestamp generation options for offline Whisper model: token-level and segment-level timestamps can now be enabled/disabled.

…nAsrNano

Add fields to Dart FFI structs that were added to the C API but missing
from the Flutter bindings, causing a struct layout mismatch and SIGSEGV
crash when creating an OfflineRecognizer.

SherpaOnnxOfflineWhisperModelConfig:
- enableTokenTimestamps (int32)
- enableSegmentTimestamps (int32)

SherpaOnnxOfflineFunAsrNanoModelConfig:
- language (Pointer<Utf8>)
- itn (int32)
- hotwords (Pointer<Utf8>)
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 14, 2026
@coderabbitai

coderabbitai Bot commented Feb 14, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR extends Flutter FFI bindings for offline speech recognition by adding configuration fields to FunASR Nano (language, itn, hotwords) and Whisper (enableTokenTimestamps, enableSegmentTimestamps) models. Changes include updates to Dart config classes, native struct definitions, serialization/deserialization methods, FFI wire-up, and memory cleanup.

Changes

Cohort / File(s) Summary
Dart Configuration Classes
flutter/sherpa_onnx/lib/src/offline_recognizer.dart
Extended OfflineFunAsrNanoModelConfig with fields: language (String), itn (int), hotwords (String). Extended OfflineWhisperModelConfig with fields: enableTokenTimestamps (bool), enableSegmentTimestamps (bool). Updated constructors, fromJson(), toString(), toJson() methods. Added FFI wire-up to convert and set these fields on native configs, and adjusted memory cleanup for newly added native fields.
Native FFI Bindings
flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
Added fields to native struct SherpaOnnxOfflineFunAsrNanoModelConfig: language (Pointer), itn (int32), hotwords (Pointer). Added fields to native struct SherpaOnnxOfflineWhisperModelConfig: enableTokenTimestamps (int32), enableSegmentTimestamps (int32).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Add Dart API for FunASR Nano #3055: Modifies the same FunASR Nano configuration types in Flutter bindings with additions to OfflineFunAsrNanoModelConfig and FFI bindings.
  • Fix various language bindings #3166: Adds the same new config fields across multiple language bindings (FunASR Nano and Whisper) with corresponding wiring and memory management updates.

Suggested labels

size:L

Suggested reviewers

  • csukuangfj

Poem

🐰 With whispers and nano FunASR so fine,
New fields now flutter in config align,
Language and tokens from strings to the streams,
Memory cleaned up in developer dreams! 🎙️✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing a SIGSEGV crash on macOS caused by missing fields in Dart FFI bindings, which is the primary objective of this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @ayoubamine, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical SIGSEGV crash on macOS by updating the Flutter Dart FFI bindings for Sherpa Onnx. The changes ensure that the Dart configuration structures accurately reflect the underlying C API, preventing runtime errors due to mismatched data structures. This significantly improves the stability and reliability of the OfflineRecognizer component, particularly on macOS platforms.

Highlights

  • Crash Fix: Resolved a SIGSEGV crash on macOS that occurred when creating an OfflineRecognizer, caused by missing fields in the Dart FFI bindings for Sherpa Onnx.
  • FFI Binding Synchronization: Synchronized the Dart FFI structs SherpaOnnxOfflineWhisperModelConfig and SherpaOnnxOfflineFunAsrNanoModelConfig with their corresponding C API definitions by adding previously omitted fields.
  • Configuration Updates: Updated OfflineFunAsrNanoModelConfig with language, itn, and hotwords properties, and OfflineWhisperModelConfig with enableTokenTimestamps and enableSegmentTimestamps.
  • Memory Management: Ensured proper memory cleanup for newly added FFI string fields in OfflineFunAsrNanoModelConfig by adding calloc.free calls.
Changelog
  • flutter/sherpa_onnx/lib/src/offline_recognizer.dart
    • Added language, itn, and hotwords parameters to the OfflineFunAsrNanoModelConfig constructor, fromJson factory, toString method, toJson method, and as final fields.
    • Added enableTokenTimestamps and enableSegmentTimestamps parameters to the OfflineWhisperModelConfig constructor, fromJson factory, toString method, toJson method, and as final fields.
    • Mapped new Whisper model configuration fields (enableTokenTimestamps, enableSegmentTimestamps) to the C FFI struct.
    • Mapped new FunAsrNano model configuration fields (language, itn, hotwords) to the C FFI struct.
    • Introduced calloc.free calls for funasrNano.hotwords and funasrNano.language to prevent memory leaks.
  • flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
    • Extended SherpaOnnxOfflineFunAsrNanoModelConfig FFI struct with language (Pointer), itn (Int32), and hotwords (Pointer) fields.
    • Extended SherpaOnnxOfflineWhisperModelConfig FFI struct with enableTokenTimestamps (Int32) and enableSegmentTimestamps (Int32) fields.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes a SIGSEGV crash on macOS by adding missing fields to the Dart FFI structs to match the C API. The changes in sherpa_onnx_bindings.dart and offline_recognizer.dart are well-implemented, ensuring the new configuration properties are handled correctly, including memory management. The fix appears solid. I've added a couple of suggestions to improve code readability by formatting long toString() methods to adhere to the Dart style guide.

@override
String toString() {
return 'OfflineFunAsrNanoModelConfig(encoderAdaptor: $encoderAdaptor, llm: $llm, embedding: $embedding, tokenizer: $tokenizer, systemPrompt: $systemPrompt, userPrompt: $userPrompt, maxNewTokens: $maxNewTokens, temperature: $temperature, topP: $topP, seed: $seed)';
return 'OfflineFunAsrNanoModelConfig(encoderAdaptor: $encoderAdaptor, llm: $llm, embedding: $embedding, tokenizer: $tokenizer, systemPrompt: $systemPrompt, userPrompt: $userPrompt, maxNewTokens: $maxNewTokens, temperature: $temperature, topP: $topP, seed: $seed, language: $language, itn: $itn, hotwords: $hotwords)';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line is very long (over 300 characters), which harms readability. The Dart style guide recommends a maximum line length of 80 characters. Please format this string literal across multiple lines for better readability and maintainability.

Suggested change
return 'OfflineFunAsrNanoModelConfig(encoderAdaptor: $encoderAdaptor, llm: $llm, embedding: $embedding, tokenizer: $tokenizer, systemPrompt: $systemPrompt, userPrompt: $userPrompt, maxNewTokens: $maxNewTokens, temperature: $temperature, topP: $topP, seed: $seed, language: $language, itn: $itn, hotwords: $hotwords)';
return 'OfflineFunAsrNanoModelConfig(' 'encoderAdaptor: $encoderAdaptor, ' 'llm: $llm, ' 'embedding: $embedding, ' 'tokenizer: $tokenizer, ' 'systemPrompt: $systemPrompt, ' 'userPrompt: $userPrompt, ' 'maxNewTokens: $maxNewTokens, ' 'temperature: $temperature, ' 'topP: $topP, ' 'seed: $seed, ' 'language: $language, ' 'itn: $itn, ' 'hotwords: $hotwords)';
References
  1. The Dart style guide recommends a line length of 80 characters. Long lines should be split for better readability. (link)

@override
String toString() {
return 'OfflineWhisperModelConfig(encoder: $encoder, decoder: $decoder, language: $language, task: $task, tailPaddings: $tailPaddings)';
return 'OfflineWhisperModelConfig(encoder: $encoder, decoder: $decoder, language: $language, task: $task, tailPaddings: $tailPaddings, enableTokenTimestamps: $enableTokenTimestamps, enableSegmentTimestamps: $enableSegmentTimestamps)';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the toString() method in OfflineFunAsrNanoModelConfig, this line is very long (over 200 characters). Please format it to adhere to the 80-character line limit for better readability.

Suggested change
return 'OfflineWhisperModelConfig(encoder: $encoder, decoder: $decoder, language: $language, task: $task, tailPaddings: $tailPaddings, enableTokenTimestamps: $enableTokenTimestamps, enableSegmentTimestamps: $enableSegmentTimestamps)';
return 'OfflineWhisperModelConfig(' 'encoder: $encoder, ' 'decoder: $decoder, ' 'language: $language, ' 'task: $task, ' 'tailPaddings: $tailPaddings, ' 'enableTokenTimestamps: $enableTokenTimestamps, ' 'enableSegmentTimestamps: $enableSegmentTimestamps)';
References
  1. The Dart style guide recommends a line length of 80 characters. Long lines should be split for better readability. (link)

@csukuangfj csukuangfj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@csukuangfj
csukuangfj merged commit 5b6e54d into k2-fsa:master Feb 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants