videokit-ai / natshare

Cross-platform social sharing for Unity Engine.
https://github.com/natmlx/videokit
Apache License 2.0
134 stars 28 forks source link

Application freeze when sharing then discarding #88

Closed aqaddoumi closed 4 years ago

aqaddoumi commented 4 years ago

Hello,

I found a bug in the sharing dialog on iOS System:

NatShare causes the application to freeze when discarding sharing, to reproduce:

`2020-04-20 18:03:28.081025+0300 app[447:40752] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "= 22 (active)>", "<NSLayoutConstraint:0x282a1c410 V:|-(15)-[_UIActivityActionCellTitleLabel:0x129d26ce0] (active, names: '|':UIView:0x129d269b0 )>", "<NSLayoutConstraint:0x282a1c460 V:[_UIActivityActionCellTitleLabel:0x129d26ce0]-(15)-| (active, names: '|':UIView:0x129d269b0 )>", "<NSLayoutConstraint:0x282a28e60 'UIView-Encapsulated-Layout-Height' UIView:0x129d269b0.height == 51.5 (active)>" )

Will attempt to recover by breaking constraint

= 22 (active)> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. 2020-04-20 18:03:28.081832+0300 effecta[447:40752] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "= 22 (active)>", "", "", "" ) Will attempt to recover by breaking constraint = 22 (active)> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. 2020-04-20 18:03:44.794616+0300 effecta[447:40779] [ShareSheet] connection invalidated libc++abi.dylib: terminating with uncaught exception of type Il2CppExceptionWrapper (lldb) `
olokobayusuf commented 4 years ago

Are you using NatShare 1.2.2? This crash should have been fixed in a previous update.

aqaddoumi commented 4 years ago

Yes I'm using NatShare 1.2.2. I don't think it's a specific problem with iPad, I've just tested on my iPhone 7 and it crashes the app but with a different error.

2020-04-22 10:31:10.072269+0300 app[712:204072] [ShareSheet] connection invalidated libc++abi.dylib: terminating with uncaught exception of type Il2CppExceptionWrapper (lldb)

I think it might have to do with the callback

  1. If I press (Mail, Messages, etc) it will take the payload to share.
  2. Then if I press discard, it will keep the native share screen.
  3. It will crash in two way:
    • Close share screen or tap outside it.
    • Tap (Mail, Messages) again and then discard again.

I'm not sure where the problem is but it highly possible that it's with the callback and might send the same result (fail) when you discard after trying to share or after discarding directly.

Lavelak commented 4 years ago

Hi, I'm running into the same problem.

So, I'm commiting a Sharepayload using an async function (see attached), then share dialog pops up. Then I choose app to share to. Another dialog pops up (see attached) asking some additional data. If option Cancel is pressed or the second dialog is swiped away, the app crashes (see xcode output attached). If Post is pressed, then everything works as it should.

I tried commiting payload without async await, but nothing changes.

This is the function I call:

async void ShareAsync()
{
      bool success = false;
      if (screenshot != null)
      {
          success = await new SharePayload().AddImage(screenshot).Commit();
      }
      else
      {
          success = await new SharePayload().AddMedia(videoPath).Commit();
      }            
      if (success)
      {
            Debug.Log("Saved to camera roll");
      }
      else
      {
          Debug.Log("Failed to save to camera roll");
      }
}

This is the output of Xcode:

2020-04-22 14:37:19.042685+0300 14[2137:1125009] [core] SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}
Failed to save to camera roll
MyCompany.TWScripts.<CheckPermissionAndSave>d__13:System.Collections.IEnumerator.get_Current()
System.Threading.ContextCallback:Invoke(Object)
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Action:Invoke()
System.Threading.ContextCallback:Invoke(Object)
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task`1:TrySetResult(TResult)
System.Threading.Tasks.TaskCompletionSource`1:TrySetResult(TResult)
System.Threading.Tasks.TaskCompletionSource`1:SetResult(TResult)
NatSuite.Sharing.Internal.NativePayload:OnCompletion(IntPtr, Boolean)

(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)2020-04-22 14:37:27.014630+0300 14[2137:1125556] [ShareSheet] connection invalidated
libc++abi.dylib: terminating with uncaught exception of type Il2CppExceptionWrapper
(lldb)

The screenshot mentioned befor (don't mind the officer protecting my privacy): Image

olokobayusuf commented 4 years ago

I'll try to reproduce and let you know. Thanks for the added info.

miketalbott commented 4 years ago

This bug still seems to be around and is reproducible with your test scene. Any updates on a fix?

olokobayusuf commented 4 years ago

@miketalbott this happens because of #56. For now, I'm just going to remove the pausing as I don't think it is important to pause Unity when the share sheet is opened.

olokobayusuf commented 4 years ago

Actually it seems that the pausing has already been removed:

https://github.com/natsuite/NatShare-API/blob/2388db6d87806d57cad59ff1e558a3335b6c9593/iOS/NatShare/NSSharePayload.m#L44-L58

It must be something else. I'll repro today.

olokobayusuf commented 4 years ago

Reproduced. Investigating now.

olokobayusuf commented 4 years ago

The crash happens because iOS invokes the completion handler twice, first when the user cancels (which gets sent to Unity), and again when the user closes the share sheet (which causes the crash):

https://github.com/natsuite/NatShare-API/blob/2388db6d87806d57cad59ff1e558a3335b6c9593/iOS/NatShare/NSSharePayload.m#L51-L55

miketalbott commented 4 years ago

yup. that would make sense because it only happens if you select an app to share with and then cancel.

miketalbott commented 4 years ago

I'm trying to get any app out today. would you have any ideas on a hot fix? should I try to modify the iOS code? (Unfortunately, I don't know ObjC).

olokobayusuf commented 4 years ago

Fixed in dab4ed60ddf883bf1fd111683bea7960e7bd039a.

olokobayusuf commented 4 years ago

@miketalbott I'm pushing all these changes to this PR: #93 . Android is WIP but iOS is all good, so you can deploy it on iOS.