react-native-compressor icon indicating copy to clipboard operation
react-native-compressor copied to clipboard

Crash on ios

Open sfedorov-at-wiley opened this issue 2 years ago • 4 comments

Current behavior

Application crashes without any logs when calling Video.compress getVideoMetaData runs fine

Expected behavior

It does not

Platform

  • [ ] Android
  • [X] iOS - Simulator without any additional config

React Native Version

0.67.1

React Native Compressor Version

1.5.2

Reproducible Steps And Demo

Just installed package, tried to run it with simplest config and it exploded We have ffmpeg installed too. Maybe this is an issue. But for such library it is nonsence to behave like that image

sfedorov-at-wiley avatar Mar 28 '22 16:03 sfedorov-at-wiley

👋 @sfedorov-at-wiley Thanks for opening your issue here! If you find this package useful hit the star🌟!

github-actions[bot] avatar Mar 28 '22 16:03 github-actions[bot]

Found crashlog

Thread 25 Crashed::  Dispatch queue: com.facebook.react.VideoCompressorQueue
0   <app_name_removed>     	       0x108da5f99 Swift runtime failure: force unwrapped a nil value + 0 [inlined]
1   <app_name_removed>     	       0x108da5f99 VideoCompressor.getfileSize(forURL:) + 2265 (VideoCompressor.swift:199)
2   <app_name_removed>     	       0x108da68c9 closure #1 in VideoCompressor.compressVideo(url:options:onProgress:onCompletion:onFailure:) + 921 (VideoCompressor.swift:212)
3   <app_name_removed>     	       0x108da7215 partial apply for closure #1 in VideoCompressor.compressVideo(url:options:onProgress:onCompletion:onFailure:) + 117
4   <app_name_removed>     	       0x108da74f5 thunk for @escaping @callee_guaranteed (@guaranteed String?) -> () + 149
5   <app_name_removed>     	       0x108d9dd22 +[ImageCompressor getAbsoluteVideoPath:completionHandler:] + 130 (ImageCompressor.m:371)
6   <app_name_removed>     	       0x108da6503 VideoCompressor.compressVideo(url:options:onProgress:onCompletion:onFailure:) + 787 (VideoCompressor.swift:209)
7   <app_name_removed>     	       0x108da14df VideoCompressor.compress(fileUrl:options:resolve:reject:) + 687 (VideoCompressor.swift:75)
8   <app_name_removed>     	       0x108da1d86 @objc VideoCompressor.compress(fileUrl:options:resolve:reject:) + 262
9   CoreFoundation                	    0x7fff2040d71c __invoking___ + 140
10  CoreFoundation                	    0x7fff2040aa8f -[NSInvocation invoke] + 305
11  CoreFoundation                	    0x7fff2040ad22 -[NSInvocation invokeWithTarget:] + 70
12  <app_name_removed>     	       0x108aafb86 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2534
13  <app_name_removed>     	       0x108ab401a facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&, int, (anonymous namespace)::SchedulingContext) + 1402
14  <app_name_removed>     	       0x108ab38cc facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const + 156
15  <app_name_removed>     	       0x108ab3829 invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) + 25
16  libdispatch.dylib             	    0x7fff201148e4 _dispatch_call_block_and_release + 12
17  libdispatch.dylib             	    0x7fff20115b25 _dispatch_client_callout + 8
18  libdispatch.dylib             	    0x7fff2011c0df _dispatch_lane_serial_drain + 753
19  libdispatch.dylib             	    0x7fff2011ccc1 _dispatch_lane_invoke + 400
20  libdispatch.dylib             	    0x7fff2012797b _dispatch_workloop_worker_thread + 779
21  libsystem_pthread.dylib       	    0x7fff6fb05fd0 _pthread_wqthread + 326
22  libsystem_pthread.dylib       	    0x7fff6fb04f57 start_wqthread + 15

sfedorov-at-wiley avatar Mar 30 '22 12:03 sfedorov-at-wiley

Found out that the reason for crash was because url was not containing 'file://' scheme Please handle this crash with try/catch properly

sfedorov-at-wiley avatar Mar 30 '22 15:03 sfedorov-at-wiley

@nomi9995 is this library still being maintained?

jpike88 avatar Jul 17 '22 16:07 jpike88

@sfedorov-at-wiley looking at your code getRealPath method is asynchronous, that should need an await keyword

deflexable avatar Oct 11 '22 12:10 deflexable

@deflexable Nope, you are not right. Code is typescript, so you would see a huge red squiggle on the screenshot in case it was really an unresolved promise.

sfedorov-at-wiley avatar Oct 11 '22 14:10 sfedorov-at-wiley

@sfedorov-at-wiley obviously the red squiggle won't show because the getRealPath wasn't declared correctly in the declaration file. The runtime of getRealPath returns a promise while the declaration file returns a "any".

so this should fix the problem:

await Video.compress(
  await getRealPath('ph://random-id/L0/001',  'video'),
  {
     compressionMethod: 'auto',
     onProgress
   }
);
Screenshot 2022-10-11 at 5 07 59 PM

deflexable avatar Oct 11 '22 16:10 deflexable

@deflexable Well, it was long time ago, but I sure that I were trying this without getRealPath and crash were happening as well. I even used debugger to check if url was passed into ios code and url was a string. But library should not hard-crash whole application if I shove a promise into it either. Just throw an exception.

So this Issue is a request for developers to fix the crash. And, as you pointed out, also fix type definitions.

sfedorov-at-wiley avatar Oct 11 '22 16:10 sfedorov-at-wiley

Do you know if this issue has been resolved? I am also stuck with the same problem.

furqancodes avatar Jan 09 '23 14:01 furqancodes