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

App crashing #28

Open
jeff-h opened this issue Jun 24, 2014 · 9 comments
Open

App crashing #28

jeff-h opened this issue Jun 24, 2014 · 9 comments

Comments

@jeff-h
Copy link
Member

jeff-h commented Jun 24, 2014

I haven't quite worked out how to reliably replicate it, but my MG2 app (actually the MG2 Documentation App) crashes quite a lot. I'm not sure what's most useful out of the crash log, or should I post the whole thing?

Here's the start of my most recent one. Or get the full thing

Process:         MacGap Documentation [32314]
Path:            /Users/USER/*/MacGap Documentation.app/Contents/MacOS/MacGap Documentation
Identifier:      com.MacGap-Documentation.docs
Version:         1.0 (1)
Code Type:       X86-64 (Native)
Parent Process:  launchd [182]
Responsible:     MacGap Documentation [32314]
User ID:         503

Date/Time:       2014-06-24 19:51:46.119 +1200
OS Version:      Mac OS X 10.9.3 (13D65)
Report Version:  11
Anonymous UUID:  8162CCD8-BAE0-3D32-34AF-595DAB2A3C19

Sleep/Wake UUID: 8720AFE9-1E34-4353-A5D6-48B3AF22C95C

Crashed Thread:  11  Dispatch queue: com.apple.root.background-priority

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: EXC_I386_GPFLT

Application Specific Information:
objc_msgSend() selector name: taskDidTerminate:

@jeff-h
Copy link
Member Author

jeff-h commented Jun 24, 2014

Another one It happened when the task ran the second time. However it's not consistent.

The task code looks like this right now:

    var gitTask = MacGap.Task.create('/bin/ls', this.gitTaskComplete);
    gitTask.arguments = ['/Users/jeffh/Desktop'];
    gitTask.pipeOutput = true;

    console.log(gitTask);
    gitTask.launch();

I wonder if it's the console.logging of the gitTask object?

@jeff-h
Copy link
Member Author

jeff-h commented Jun 24, 2014

You can see what I'm trying to do from line 34 at https://github.com/MacGapProject/documentation-app/blob/master/public/models/pageModel.js

@rawcreative
Copy link
Member

The bad access exceptions are happening because whatever you're trying to call/access has already been released from memory and no longer exists. It's probably because you're trying to make a subsequent call to the task. NSTask is a single use object, once it's been launched it cannot be launched/used again and will throw exceptions if you try to access methods or interact with the task again.

Like I mentioned before, if you're trying to do complex stuff with NSTask, you're going to have to do it in Obj-c, not with the MacGap Task command as there's just entirely too many variables to account for. I'm honestly not entirely sure why you would even need to use NSTask for a documentation app anyway? It looks like you're wanting to use 'git', but git isn't installed on OSX by default, so the whole app would be unusable if you're relying on that and someone didn't have git installed.

@jeff-h
Copy link
Member Author

jeff-h commented Jun 24, 2014

Thanks so much for looking into this. Do you have a sample piece of code for the task command and new pipeOutut that shows it working? I can't see anything that I'm doing wrong and I've tried to create the simplest case I can think of (ls).

It does only happen when I reload the page inside the MacGap window without restarting the app.

Regarding the docs app, I'd like it to work offline because a) I'm often offline and b) I'd like to break any concept that MacGap is a glorified Fluid app equivalent (i.e. only useful to wrap around a page pulled live from the web).

I'm also trying to demo as many of the commands as I can, so I had the notion that I could demo the task command to use git to pull in the repo on each app launch, thereby keeping everyone's docs up-to-date. I've bundled a git binary into the app. In terms of the actual commands it should be pretty trivial.

@rawcreative
Copy link
Member

This code works fine:

var myTask = MacGap.Task.create('/bin/ls',function(results) {
    console.log(results);
});
myTask.pipeOutput = true;
myTask.launch();

It should return an object with the stdOut of "MG.app" or similar. Setting the 'environment' like you are doing isn't correct, the environment property of NSTask is for setting/adjusting environment variables, which you don't need to do since the task inherits the callers environment, i.e. your app.

The main issue you're going to run into is that piping the output is, for the most part useless. This is because whatever the output happens to be, it has to be converted to a string to be returned to javascript. So with the ls example, if you run it in a directory with multiple files, it just returns a string representation of the contents, i.e. "file.txt↵file2.txt↵something.js↵index.html" etc. It doesn't really do you any good.

@jeff-h
Copy link
Member Author

jeff-h commented Jun 26, 2014

Thanks for this — I'm still playing with it, but was hoping you could explain one aspect for me. I'm trying to understand how the properties work when there is more than one task instantiated from JS.

For example, at face value it looks like .createTask() simply overwrites the task property with a new NSTask, possibly clobbering an existing task.

@perifer
Copy link
Contributor

perifer commented Jun 26, 2014

Would it possible to simplify the API? I'm thinking that

var myTask = MacGap.Task.create('/bin/ls',function(results) {
    console.log(results);
});
myTask.pipeOutput = true;
myTask.launch();

instead could be something like

var myTask = MacGap.execute('/bin/ls', function(stdout) {
    console.log(stdout);
});

Drawing inspiration from e.g. http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback and the just released Javascript Actions API for Launchbar: http://www.obdev.at/resources/launchbar/developer-documentation/javascript-launchbar.html#//apple_ref/cpp/Method/execute

Launchbar has some interesting stuff in their API, e.g HTTP: http://www.obdev.at/resources/launchbar/developer-documentation/index.html#LaunchBarJavaScriptReference

@jeff-h
Copy link
Member Author

jeff-h commented Jun 26, 2014

It's a good point — I've moved this to a new issue as it's unrelated to the app crashing one.

@perifer
Copy link
Contributor

perifer commented Jun 27, 2014

True, thanks. Moved HTTP to #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants