cunarist / rinf

Rust for native business logic, Flutter for flexible and beautiful GUI
MIT License
1.72k stars 63 forks source link

App Crash on send signal to dart method call in my Samsung A13 phone #368

Open nikunjOceanmtech opened 1 month ago

nikunjOceanmtech commented 1 month ago

F/libc (10287): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 10446 (1.ui), pid 10287 (library_flutter)


Build fingerprint: 'samsung/a13nnxx/a13:14/UP1A.231005.007/A135FXXS7DXE4:user/release-keys' Revision: '6' ABI: 'arm' Processor: '3' Timestamp: 2024-06-11 13:14:43.398759947+0530 Process uptime: 22s Cmdline: com.example.image_processing_library_flutter pid: 10287, tid: 10446, name: 1.ui >>> com.example.image_processing_library_flutter <<< uid: 10327 signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- r0 00000000 r1 000028ce r2 00000006 r3 bb104850 r4 bb104860 r5 bb104848 r6 0000282f r7 0000016b r8 00000000 r9 ffffffff r10 bb104850 r11 bb104b20 ip 000028ce sp bb104830 lr e454a113 pc e454a126 3 total frames backtrace:

00 pc 00063126 /apex/com.android.runtime/lib/bionic/libc.so (abort+138) (BuildId: adc8d9e6a9ef4c96683727240de4565c)

  #01 pc 003872d1  /data/app/~~MdqyNSZFJPa5jrJbzLh9pg==/com.example.image_processing_library_flutter-n667SZi86C_b6wtGctRx9w==/lib/arm/libhub.so
  #02 pc 001fe96e  [anon:stack_and_tls:10446]

Lost connection to device.

Exited.

this crash message showing

.toml file code is

[package]
edition = "2021"
name = "hub"
version = "0.1.0"

[lib]
crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
image = "0.24"
imageproc = "0.23"
num-derive = "0.4.2"
num-traits = {version = "0.2.0"}
prost = "0.12.3"
rinf = "6.11.1"
rusttype = "0.9.3"
tokio = {version = "1", features = ["rt-multi-thread", "sync", "macros"]}

.proto file code is

syntax = "proto3";
package basic;

// [RINF:RUST-SIGNAL]
message OverlayOutputData { bytes output_image = 1; }

// [RINF:DART-SIGNAL]
message OverlayInputData {
  bytes input_image = 1; // Background Image Path

  bytes overlay_image1 = 2; // Overly First Image Path
  int32 overlay_image1_width = 3;  // Field for the width of the overlay
  int32 overlay_image1_height = 4; // Field for the height of the overlay
  int32 overlay_image1_x = 5; // Field for the x-coordinate of the overlay position
  int32 overlay_image1_y = 6; // Field for the y-coordinate of the overlay position

  bytes overlay_image2 = 7; // Overly Second Image Path
  int32 overlay_image2_width = 8;  // Field for the width of the overlay
  int32 overlay_image2_height = 9; // Field for the height of the overlay
  int32 overlay_image2_x = 10; // Field for the x-coordinate of the overlay position
  int32 overlay_image2_y = 11; // Field for the y-coordinate of the overlay position

  string overlay_name = 12;
  bytes overlay_name_font_family = 13;
  int32 overlay_name_font_x = 14;
  int32 overlay_name_font_y = 15;
  float overlay_name_font_size = 16;
  int32 overlay_name_font_color = 17;

  string overlay_number = 18;
  bytes overlay_number_font_family = 19;
  int32 overlay_number_font_x = 20;
  int32 overlay_number_font_y = 21;
  float overlay_number_font_size = 22;
  int32 overlay_number_font_color = 23;

  string overlay_address = 24;
  bytes overlay_address_font_family = 25;
  int32 overlay_address_font_x = 26;
  int32 overlay_address_font_y = 27;
  float overlay_address_font_size = 28;
  int32 overlay_address_font_color = 29;

  string overlay_email = 30;
  bytes overlay_email_font_family = 31;
  int32 overlay_email_font_x = 32;
  int32 overlay_email_font_y = 33;
  float overlay_email_font_size = 34;
  int32 overlay_email_font_color = 35;

  string overlay_company = 36;
  bytes overlay_company_font_family = 37;
  int32 overlay_company_font_x = 38;
  int32 overlay_company_font_y = 39;
  float overlay_company_font_size = 40;
  int32 overlay_company_font_color = 41;

  string overlay_address1 = 42;
  bytes overlay_address1_font_family = 43;
  int32 overlay_address1_font_x = 44;
  int32 overlay_address1_font_y = 45;
  float overlay_address1_font_size = 46;
  int32 overlay_address1_font_color = 47;
}

.rs file code is

#![allow(unused_imports)]
#![allow(unused)]
#![allow(deprecated)]
extern crate image;

mod messages;

use image::imageops::FilterType;
use image::Rgb;
use image::{
    imageops::overlay, DynamicImage, ExtendedColorType, GenericImageView, ImageBuffer,
    ImageEncoder, Rgba, RgbaImage,
};
use imageproc::drawing::{draw_text_mut, text_size};
use rinf::debug_print;
use rusttype::{point, Font, Scale};
use std::fs::File;
use std::io::Cursor;
use std::path::Path;
use std::{env, fs};
use tokio;

rinf::write_interface!();

async fn main() {
    use messages::basic::*;

    let mut receiver = OverlayInputData::get_dart_signal_receiver();

    while let Some(dart_signal) = receiver.recv().await {
        let my_precious_data = dart_signal.message;

        // Load images from memory
        let mut background =
            image::load_from_memory(&my_precious_data.input_image).expect("Image Not Load");

        // Apply the overlay at specified coordinates fream logo
        let mut result: RgbaImage = ImageBuffer::new(background.width(), background.height());
        if (!my_precious_data.overlay_image1.is_empty()) {
            let overlay_image1 =
                image::load_from_memory(&my_precious_data.overlay_image1).expect("Image Not Load");
            image::imageops::replace(&mut result, &background, 0, 0);
            let overlay_x1 = my_precious_data.overlay_image1_x as i64;
            let overlay_y1 = my_precious_data.overlay_image1_y as i64;
            overlay(&mut result, &overlay_image1, overlay_x1, overlay_y1);
        }

        // Apply the overlay at specified coordinates overly logo
        if (!my_precious_data.overlay_image2.is_empty()) {
            let overlay_image2 =
                image::load_from_memory(&my_precious_data.overlay_image2).expect("Image Not Load");
            let overlay_width = my_precious_data.overlay_image2_width as u32;
            let overlay_height = my_precious_data.overlay_image2_height as u32;
            let resized_overlay_img =
                overlay_image2.resize(overlay_width, overlay_height, FilterType::Lanczos3);

            let overlay_x1 = my_precious_data.overlay_image2_x as i64;
            let overlay_y1 = my_precious_data.overlay_image2_y as i64;
            overlay(&mut result, &resized_overlay_img, overlay_x1, overlay_y1);
        }

        // Apply the overlay at specified coordinates Text Name
        if (!my_precious_data.overlay_name.is_empty()) {
            let text = my_precious_data.overlay_name;
            let color = Rgba([255, 255, 255, 255]);
            // let color = Rgb([0, 0, 0]);
            let font_bytes = my_precious_data.overlay_name_font_family;
            let font = Font::try_from_bytes(&font_bytes).expect("Error constructing Font");
            let font_size = &my_precious_data.overlay_name_font_size;
            let scale = Scale::uniform(*font_size);
            draw_text_mut(
                &mut result,
                color,
                my_precious_data.overlay_name_font_x,
                my_precious_data.overlay_name_font_y,
                scale,
                &font,
                &text,
            );
        }

        // Apply the overlay at specified coordinates Text Number
        if (!my_precious_data.overlay_number.is_empty()) {
            let text = my_precious_data.overlay_number;
            let color = Rgba([255, 255, 255, 255]);
            let font_bytes = my_precious_data.overlay_number_font_family;
            let font = Font::try_from_bytes(&font_bytes).expect("Error constructing Font");
            let font_size = &my_precious_data.overlay_number_font_size;
            let scale = Scale::uniform(*font_size);
            draw_text_mut(
                &mut result,
                color,
                my_precious_data.overlay_number_font_x,
                my_precious_data.overlay_number_font_y,
                scale,
                &font,
                &text,
            );
        }

        // Apply the overlay at specified coordinates Text Address
        if (!my_precious_data.overlay_address.is_empty()) {
            let text = my_precious_data.overlay_address;
            let color = Rgba([0, 0, 0, 255]);
            let font_bytes = my_precious_data.overlay_address_font_family;
            let font = Font::try_from_bytes(&font_bytes).expect("Error constructing Font");
            let font_size = &my_precious_data.overlay_address_font_size;
            let scale = Scale::uniform(*font_size);
            draw_text_mut(
                &mut result,
                color,
                my_precious_data.overlay_address_font_x,
                my_precious_data.overlay_address_font_y,
                scale,
                &font,
                &text,
            );
        }

        // Apply the overlay at specified coordinates Text Address1
        if (!my_precious_data.overlay_address1.is_empty()) {
            let text = my_precious_data.overlay_address1;
            let color = Rgba([0, 0, 0, 255]);
            let font_bytes = my_precious_data.overlay_address1_font_family;
            let font = Font::try_from_bytes(&font_bytes).expect("Error constructing Font");
            let font_size = &my_precious_data.overlay_address1_font_size;
            let scale = Scale::uniform(*font_size);
            draw_text_mut(
                &mut result,
                color,
                my_precious_data.overlay_address1_font_x,
                my_precious_data.overlay_address1_font_y,
                scale,
                &font,
                &text,
            );
        }

        // Apply the overlay at specified coordinates Text company
        if (!my_precious_data.overlay_company.is_empty()) {
            let text = my_precious_data.overlay_company;
            let color = Rgba([0, 0, 0, 255]);
            let font_bytes = my_precious_data.overlay_company_font_family;
            let font = Font::try_from_bytes(&font_bytes).expect("Error constructing Font");
            let font_size = &my_precious_data.overlay_company_font_size;
            let scale = Scale::uniform(*font_size);
            draw_text_mut(
                &mut result,
                color,
                my_precious_data.overlay_company_font_x,
                my_precious_data.overlay_company_font_y,
                scale,
                &font,
                &text,
            );
        }

        // Apply the overlay at specified coordinates Text email
        if (!my_precious_data.overlay_email.is_empty()) {
            let text = my_precious_data.overlay_email;
            let color = Rgba([0, 0, 0, 255]);
            let font_bytes = my_precious_data.overlay_email_font_family;
            let font = Font::try_from_bytes(&font_bytes).expect("Error constructing Font");
            let font_size = &my_precious_data.overlay_email_font_size;
            let scale = Scale::uniform(*font_size);
            draw_text_mut(
                &mut result,
                color,
                my_precious_data.overlay_email_font_x,
                my_precious_data.overlay_email_font_y,
                scale,
                &font,
                &text,
            );
        }

        // Convert the result to a Vec<u8> using PngEncoder
        let mut result_buffer = Vec::new();
        let mut cursor = Cursor::new(&mut result_buffer);
        let encoder = image::codecs::png::PngEncoder::new(&mut cursor);
        encoder.encode(
            &result,
            result.width(),
            result.height(),
            image::ColorType::Rgba8,
        );

        // Send the result to Dart
        OverlayOutputData {
            output_image: result_buffer,
        }
        .send_signal_to_dart();

        debug_print!("Overlay applied and sent to Dart");
    }
}
temeddix commented 1 month ago

Hi @nikunjOceanmtech , thanks for the report :)

It looks like A13 phone has 32-bit Android OS. I'll will check how Rinf behaves on 32-bit systems, though not sure exactly when I would be able to do that.

nikunjOceanmtech commented 1 month ago

Hi @nikunjOceanmtech , thanks for the report :)

It looks like A13 phone has 32-bit Android OS. I'll will check how Rinf behaves on 32-bit systems, though not sure exactly when I would be able to do that.

@temeddix ,

i am create new flutter project then add rinf: ^6.12.1 this package then follow this website https://rinf.cunarist.com/applying-template/ and then method call to show same error

this my flutter project link https://github.com/nikunjOceanmtech/image_library_rust

https://github.com/cunarist/rinf/assets/147715598/1216cb36-1e52-4ad4-b1f5-5979fa319b87

utaite commented 2 weeks ago

It is not supported on 32-bit Android OS such as Samsung Galaxy A13 and Samsung Galaxy Tab A 10.1.