react-native-star-io10 icon indicating copy to clipboard operation
react-native-star-io10 copied to clipboard

[BUG] android application crashes on image with OOM with printImage

Open darrenjaworski opened this issue 1 year ago • 6 comments

Description

Android application crashes on print with image (png). This same image works fine on iOS implementation. Identified in stack trace where the out of memory exception is occuring, seems to be in actionPrintImage in the underlying android star library. The image is only 0.2 MB and should not be causing out of memory exceptions.

Started using on actual android device and crashes for the same reason but with even smaller images.

stack trace included:

"mqt_native_modules" prio=5 tid=6 Runnable
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:   | group="main" sCount=0 dsCount=0 flags=2 obj=0x12c4a7e0 self=0x7356c63400
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:   | sysTid=4258 nice=0 cgrp=default sched=0/0 handle=0x72c22c0d50
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:   | state=R schedstat=( 983805412 105429828 1444 ) utm=91 stm=6 core=2 HZ=100
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:   | stack=0x72c21be000-0x72c21c0000 stackSize=1039KB
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:   | held mutexes= "mutator lock"(shared held)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at com.starmicronics.stario10.util.d.<init>(unavailable:-1)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at com.starmicronics.stario10.starxpandcommand.PrinterBaseBuilder$Companion.actionPrintImage(unavailable:-1)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at com.starmicronics.stario10.starxpandcommand.PrinterBuilder.actionPrintImage(unavailable:-1)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at com.stario10module.PrinterBuilderWrapper.actionPrintImage(PrinterBuilderWrapper.kt:333)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at java.lang.reflect.Method.invoke(Native method)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at com.facebook.react.bridge.queue.NativeRunnable.run(Native method)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at android.os.Handler.handleCallback(Handler.java:883)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at android.os.Handler.dispatchMessage(Handler.java:100)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
2022-07-15 15:49:45.481 4185-4258/com.hpos W/com.hpos:     at android.os.Looper.loop(Looper.java:214)

Your device where the bug occurs

  • Device: android tablet simulator/ actual tablet device
  • OS: android 10 - Q

Your printer

  • Model Names: star tsp100iii
  • Firmware Version: no idea
  • Interface: wps

Your development environment

ProductName: macOS ProductVersion: 12.2 BuildVersion: 21D49


System: OS: macOS 12.2 CPU: (10) arm64 Apple M1 Pro Memory: 93.78 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 18.5.0 - /opt/homebrew/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn npm: 8.12.1 - /opt/homebrew/bin/npm Watchman: Not Found Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: Not Found IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8609683 Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild Languages: Java: 17.0.2 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.1 => 0.68.1 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

To Reproduce

Steps to reproduce the behavior:

  1. invoke below the function with provided images on android emulator/device:
const imageParameter = new ImageParameter(printImageUri, 580);
const document = new StarXpandCommand.DocumentBuilder().addPrinter(
  new StarXpandCommand.PrinterBuilder()
    .actionPrintImage(imageParameter)
    .actionCut(StarXpandCommand.Printer.CutType.Partial),
);
		
const builder = new StarXpandCommand.StarXpandCommandBuilder();

builder.addDocument(document);

const commands = await builder.getCommands();
await printer.open();
await printer.print(commands);

Expected behavior

Expected library to trigger print for image in android.

Screenshots

Screen Shot 2022-07-15 at 3 50 04 PM

Screen Shot 2022-07-15 at 2 47 06 PM

Additional context

Example images that is attempted to be printed.

ReactNative-snapshot-image8481380400877701547

ReactNative-snapshot-image2439692663781395881

darrenjaworski avatar Jul 15 '22 20:07 darrenjaworski

@darrenjaworski Thank you for your report. However, when I tried, this issue did not reproduce.

My procedure

  1. Downloaded the latest SDK (V1.2.0) from GitHub.
  2. Saved your two example images as "sample.png" and "sample2.png" in the folder of "example/android/app/src/main/res/drawable".
  3. Changed the sample code in App.tsx as described in your reproduction procedure. printImageUri is substituted "sample.png" or "sample2.png".
  4. Executed the npx react-native run-android command with the actual Android Device (Pixel 4a Android 12) and the virtual one.
  5. Confirmed that both sample data were printed successfully on the actual device and on the emulator.

My environment

% sw_vers
ProductName:	macOS
ProductVersion:	12.4
BuildVersion:	21F79

% npx react-native info
info Fetching system and libraries information...
System:
    OS: macOS 12.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 47.38 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nodebrew/current/bin/node
    Yarn: 1.22.19 - ~/.nodebrew/current/bin/yarn
    npm: 8.14.0 - ~/.nodebrew/current/bin/npm
    Watchman: 2022.07.04.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK:
      API Levels: 27, 29, 30, 31, 32
      Build Tools: 29.0.2, 30.0.2, 30.0.3, 32.0.0, 32.1.0
      System Images: android-31 | Google APIs Intel x86 Atom_64
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8609683
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.11 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.67.2 => 0.67.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Could you please let us know how to specify the source parameter of ImageParameter method?

bandit-ibayashi avatar Jul 20 '22 03:07 bandit-ibayashi

Thanks for responding to the issue! It's been really stumping us and actually from your response we were able to discover more about this weird issue.

This seems to be directly related to the RAM usage of the app. Somewhere around 220MB this issue occurs. This is a big concern our RN app typically sits around that point. Where we currently are printing, this issue occurs even with a small image. (On physical device we can't even print the smallest image we have, the app crashes)

Given that the android simulators we have tested on are configured with 4 GB of RAM this should be no issue, so I'm wondering if some of the lower level java bitmap code could be the issue here.

To help make it easier to reproduce, here is a repo with a bunch of kittens and a print button. This includes a sample creating the ImageParameter like you asked

  • https://github.com/KodyFintak/starprinttest

It does print a lot of images on screen... but RAM usage is close to what our actually app uses.

link to print code

Reproduction Steps:

  1. setup simulator with 4 GB of RAM
  2. yarn && yarn android
  3. click the print button

(you can use the profiler in android studio to validate the amount of RAM being used)

iOS does not exhibit this behavior, even on an iPAD with less RAM.

KodyFintak avatar Jul 20 '22 22:07 KodyFintak

@KodyFintak Thank you very much for your information and sample project for this issue. I'm sure this information will be helpful in the analysis of this issue.

I'm trying to reproduce the error on your sample, but have not yet been able to reproduce the same error. The following errors may also occur and I will check them together.

 LOG  Running "starprinttest" with {"rootTag":1}
 WARN  Possible Unhandled Promise Rejection (id: 0):
StarIO10InUseError: The device is in use by another process.
construct@[native code]
construct@[native code]
_construct@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:23519:28
Wrapper@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:23479:64
construct@[native code]
_createSuperInternal@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:113775:322
StarIO10Error@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:113789:26
construct@[native code]
_createSuperInternal@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:113980:322
StarIO10InUseError@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:113991:26
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:113670:103
generatorResume@[native code]
asyncGeneratorStep@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:24715:26
_next@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:24737:29
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:24744:14
tryCallTwo@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:28940:9
doResolve@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:29104:25
Promise@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:28963:14
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:24733:25
_buildObject@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:113711:37
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:113630:60
generatorResume@[native code]
asyncGeneratorStep@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:24715:26
_next@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:24737:29
tryCallOne@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:28931:16
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:29032:27
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:30196:26
_callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:30096:17
_callReactNativeMicrotasksPass@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:30131:17
callReactNativeMicrotasks@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:30339:44
__callReactNativeMicrotasks@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:3025:46
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:2803:45
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:3008:15
flushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.starprinttest&modulesOnly=false&runModule=true:2802:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]

I appreciate your patience.

bandit-ibayashi avatar Jul 21 '22 11:07 bandit-ibayashi

@bandit-ibayashi Ah got it, let me send over the exact simulator details we are using to help recreate the issue.

Here is a screenshot of a device configuration I was able to get to crash with the linked kitten project above.

Screen Shot 2022-07-21 at 1 04 19 PM

The RAM is the same as our physical device but I'm unsure of the VM Heap setting. I'm taking some time to figure that out but the issue still occurs on the simulator above.

I ran this with a profiler and figured it would be helpful to show the spike when I click "print" and show the crash of the app.

Screen Shot 2022-07-21 at 1 03 29 PM

The following errors may also occur and I will check them together. StarIO10InUseError: The device is in use by another process.

This error is probably from clicking the print button multiple times. In our case that shouldn't be an issue so I think that problem is unrelated?

Thanks again for taking a look into this!

KodyFintak avatar Jul 21 '22 17:07 KodyFintak

@KodyFintak Thank you for your more detailed report. But somehow I have not yet been able to reproduce this problem using an Android emulator with the same settings.

I also don't think the StarIO10InUseError is related to this Issue either, but it also occurs on the first tap after launching the app. (I clicked the button carefully to avoid double tapping).

I will continue to analyse this Issue. I appreciate your patience.

bandit-ibayashi avatar Jul 25 '22 09:07 bandit-ibayashi

Sounds good. Thanks again for looking into this.

If it helps we could talk for 30 over a video chat sometime next week. That way I can exactly show the issue that's going on and we can try to work through it together.

KodyFintak avatar Jul 29 '22 14:07 KodyFintak