Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create Modal from Task callback #137

Closed
metakirby5 opened this issue Aug 22, 2016 · 10 comments
Closed

Unable to create Modal from Task callback #137

metakirby5 opened this issue Aug 22, 2016 · 10 comments
Assignees
Labels
Milestone

Comments

@metakirby5
Copy link
Contributor

metakirby5 commented Aug 22, 2016

  • Version: 2.3 (49)
  • macOS: 10.11.6 (15G31)

I tried to use Task.run to start a task that launches a modal with output from a shell command in CoffeeScript, as follows:

Task.run '/bin/sh', [
  "-c", "date"
], (r) ->
  Phoenix.log r.output
  sf = Space.active().screen().frame()
  Modal.build
    text: r.output
    weight: p.modals.weight
    appearance: p.modals.appearance
    origin: (mf) ->
      x: sf.x + sf.width / 2 - mf.width / 2
      y: sf.y + sf.height / 2 - mf.height / 2
  .show()

The modal does not show up. However, the output is logged by the Phoenix.log call, indicating that the callback did not fail. Additionally, I verified that the Modal.build would not have failed under normal circumstances by un-indenting the relevant lines.

I get a lot of similar looking messages in Console, the last of which is:

8/22/16 00:03:02.063 Phoenix[43473]: This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release.
 Stack:(
    0   CoreFoundation                      0x00007fff90b5b4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff86eb3f7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff90bc24bd +[NSException raise:format:] + 205
    3   Foundation                          0x00007fff86b461f1 _AssertAutolayoutOnMainThreadOnly + 79
    4   Foundation                          0x00007fff86b4cf54 -[NSISEngine optimize] + 49
    5   Foundation                          0x00007fff86b4611b -[NSISEngine withBehaviors:performModifications:] + 244
    6   AppKit                              0x00007fff8f679ac4 __97-[NSWindow(NSConstraintBasedLayout) _fromConstraintsGetWindowMinSize:maxSize:allowDynamicLayout:]_block_invoke + 883
    7   Foundation                          0x00007fff86b460c2 -[NSISEngine withBehaviors:performModifications:] + 155
    8   AppKit                              0x00007fff8f5e105e -[NSWindow(NSConstraintBasedLayout) _fromConstraintsGetWindowMinSize:maxSize:allowDynamicLayout:] + 568
    9   AppKit                              0x00007fff8f5e0d9b -[NSWindow(NSConstraintBasedLayout) _getConstrainedWindowMinSize:maxSize:] + 47
    10  AppKit                              0x00007fff8f5e0cca -[NSWindow minFullScreenContentSize] + 77
    11  AppKit                              0x00007fff8f7d3083 -[NSWindow _minFullScreenContentSizeForFrame:] + 31
    12  AppKit                              0x00007fff8f7d305c -[NSWindow _actualMinFullScreenContentSize] + 100
    13  AppKit                              0x00007fff8f607f34 -[NSWindow _updateCGWindowSizesForTiling] + 81
    14  AppKit                              0x00007fff8f5d439b -[NSWindow _setWindowNumber:] + 688
    15  AppKit                              0x00007fff8f775db1 _NSCreateWindow + 207
    16  AppKit                              0x00007fff8f7c26c0 -[NSWindow _commonAwake] + 1516
    17  AppKit                              0x00007fff8f7c2062 -[NSWindow _makeKeyRegardlessOfVisibility] + 85
    18  AppKit                              0x00007fff8f6fb325 NSPerformVisuallyAtomicChange + 147
    19  AppKit                              0x00007fff8f7c1fab -[NSWindow makeKeyAndOrderFront:] + 79
    20  QuickLookUI                         0x00007fff855f1ec3 -[QLSeamlessDocumentOpener showWindow:contentFrame:withBlock:] + 108
    21  AppKit                              0x00007fff8f7c10c7 -[NSWindowController showWindow:] + 434
    22  Phoenix                             0x000000010695094d -[PHModalWindowController show] + 96
    23  CoreFoundation                      0x00007fff90acca6c __invoking___ + 140
    24  CoreFoundation                      0x00007fff90acc8fe -[NSInvocation invoke] + 286
    25  JavaScriptCore                      0x00007fff8ebf4673 _ZN3JSC24ObjCCallbackFunctionImpl4callEP9JSContextP13OpaqueJSValuemPKPKS3_PS6_ + 451
    26  JavaScriptCore                      0x00007fff8ebf41e6 _ZN3JSCL34objCCallbackFunctionCallAsFunctionEPK15OpaqueJSContextP13OpaqueJSValueS4_mPKPKS3_PS6_ + 262
    27  JavaScriptCore                      0x00007fff8ebf4d8d _ZN3JSC19APICallbackFunction4callINS_20ObjCCallbackFunctionEEExPNS_9ExecStateE + 573
    28  JavaScriptCore                      0x00007fff8e6dfd90 _ZN3JSC5LLInt9setUpCallEPNS_9ExecStateEPNS_11InstructionENS_22CodeSpecializationKindENS_7JSValueEPNS_17LLIntCallLinkInfoE + 528
    29  JavaScriptCore                      0x00007fff8ebdc64d llint_entry + 22900
    30  JavaScriptCore                      0x00007fff8ebdc658 llint_entry + 22911
    31  JavaScriptCore                      0x00007fff8ebdc658 llint_entry + 22911
    32  JavaScriptCore                      0x00007fff8ebd6ac9 vmEntryToJavaScript + 326
    33  JavaScriptCore                      0x00007fff8eb047b9 _ZN3JSC7JITCode7executeEPNS_2VMEPNS_14ProtoCallFrameE + 169
    34  JavaScriptCore                      0x00007fff8e6e25ed _ZN3JSC11Interpreter11executeCallEPNS_9ExecStateEPNS_8JSObjectENS_8CallTypeERKNS_8CallDataENS_7JSValueERKNS_7ArgListE + 493
    35  JavaScriptCore                      0x00007fff8e6e23ee _ZN3JSC4callEPNS_9ExecStateENS_7JSValueENS_8CallTypeERKNS_8CallDataES2_RKNS_7ArgListE + 62
    36  JavaScriptCore                      0x00007fff8e6e2319 JSObjectCallAsFunction + 697
    37  JavaScriptCore                      0x00007fff8e82858e -[JSValue callWithArguments:] + 286
    38  Phoenix                             0x0000000106950ef8 -[PHHandler callWithArguments:] + 126
    39  Phoenix                             0x0000000106947b24 -[PHTaskHandler taskDidTerminate] + 96
    40  Phoenix                             0x000000010694791a __40-[PHTaskHandler setupTerminationHandler]_block_invoke + 609
    41  Foundation                          0x00007fff86cd00fe __39-[NSConcreteTask launchWithDictionary:]_block_invoke_3 + 20
    42  libdispatch.dylib                   0x00007fff96b5993d _dispatch_call_block_and_release + 12
    43  libdispatch.dylib                   0x00007fff96b4e40b _dispatch_client_callout + 8
    44  libdispatch.dylib                   0x00007fff96b5229b _dispatch_root_queue_drain + 1890
    45  libdispatch.dylib                   0x00007fff96b51b00 _dispatch_worker_thread3 + 91
    46  libsystem_pthread.dylib             0x00007fff858a84de _pthread_wqthread + 1129
    47  libsystem_pthread.dylib             0x00007fff858a6341 start_wqthread + 13
)

Let me know if you need the full output -- it's a bit long.

@kasper
Copy link
Owner

kasper commented Aug 22, 2016

What happens if you keep a reference to the modal? It’s probably getting released.

@metakirby5
Copy link
Contributor Author

By keeping a reference, do you mean to replace the callback function with something similar to the following block?

  Phoenix.log r.output
  sf = Space.active().screen().frame()
  status = Modal.build
    text: r.output
    duration: p.modals.duration
    weight: p.modals.weight
    appearance: p.modals.appearance
    origin: (mf) ->
      x: sf.x + sf.width / 2 - mf.width / 2
      y: sf.y + sf.height / 2 - mf.height / 2
  status.show()

With this callback, the same results are observed.

@metakirby5
Copy link
Contributor Author

metakirby5 commented Aug 22, 2016

I also tried instantiating the modal from outside of the callback, and instead setting the text and showing the modal in the callback, with the same results:

sf = Space.active().screen().frame()
status = Modal.build
  duration: p.modals.duration
  weight: p.modals.weight
  appearance: p.modals.appearance
  origin: (mf) ->
    x: sf.x + sf.width / 2 - mf.width / 2
    y: sf.y + sf.height / 2 - mf.height / 2

Task.run '/bin/sh', [
  "-c", "date"
], (r) ->
  Phoenix.log r.output
  status.text = r.output
  status.show()

EDIT: I forgot to mention, p.modals.* is just a configuration dictionary I have. They can be thought of as constants.

@kasper
Copy link
Owner

kasper commented Aug 22, 2016

@metakirby5 Ok, thanks! I’ll look into this. I wonder why (or if) this only happens with Task callbacks.

@metakirby5
Copy link
Contributor Author

Seems like Timer calls don't work either:

Task.run '/bin/sh', [
  "-c", "date"
], (r) ->
  Phoenix.log '1'
  Timer.after 0, -> Phoenix.log '2'
Timer.after 0, -> Phoenix.log '3'

I get:

Phoenix: 1
Phoenix: Context loaded.
Phoenix: 3

@kasper
Copy link
Owner

kasper commented Aug 27, 2016

@metakirby5 Very intriguing, thanks for the information! I started a new job, so it will take me a bit longer to sort these, but hopefully very soon. Sorry for the wait!

@kasper
Copy link
Owner

kasper commented Aug 27, 2016

By the way, have you tried testing this with an unmanaged Task? There might be an issue in how the instances are getting released in this scenario.

@metakirby5
Copy link
Contributor Author

@kasper Same symptoms, unfortunately :(

mytask = new Task '/bin/sh', [
  "-c", "date"
], (r) ->
  Phoenix.log '1'
  Timer.after 0, -> Phoenix.log '2'
Timer.after 0, -> Phoenix.log '3'

Tested it with the Modal as well, but you can probably tell how the code for that looks.

Also, no worries about the delay! I found Phoenix.notify (which still works) to be a reasonable alternative for the time being. Good luck on the new job :)

@kasper kasper added the bug label Nov 19, 2016
@kasper kasper added this to the 2.4 milestone Nov 19, 2016
@kasper kasper self-assigned this Nov 19, 2016
@kasper
Copy link
Owner

kasper commented Nov 19, 2016

@metakirby5 Found the cause, which is pretty obvious from the stack trace. Since tasks are now run asynchronously, the callback is getting called from another thread which causes issues. You can among other things only update the UI from the main thread.

@kasper
Copy link
Owner

kasper commented Nov 19, 2016

Fixed in master. Sorry for the wait!

@kasper kasper closed this as completed Nov 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants