将OSX Obj-C / CG截屏代码移植到js-ctypes - 在最后一行崩溃 [英] Ported OSX Obj-C/CG Screenshot Code to js-ctypes - crash on final line

查看:231
本文介绍了将OSX Obj-C / CG截屏代码移植到js-ctypes - 在最后一行崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植了一些Objective-C / CoreGraphics代码,它能够截取多个显示器的屏幕截图,但不起作用。 jsctypes家伙将无法帮助,因为该部分只是我回答问题lol



objc / cg代码是从这里: https://stackoverflow.com/a/28247749/1828637



我的jsctypes类型/结构/声明在这里: https://github.com/Noitidart /NativeShot/blob/mac-troubleshooting/modules/ostypes_mac.jsm



jsctypes端口在这里: https://github.com/Noitidart/NativeShot/blob/mac-troubleshooting/modules /workers/MainWorker.js#L443-656



最后一行是643行,导致崩溃:

  var rez_writeToFile = ostypes.API('objc_msgSend')(data,ostypes.HELPER.sel 'writeTofile:atomically:'),myNSStrings.get(OS.Path.join(OS.Constants.Path.desktopDir,'full_ss.png')),ostypes.CONST.YES); 

这符合

<$ p的目标$ p> [data writeToFile:@/ tmp / screenshot.pngatomically:YES];

除了我更改路径...桌面/ ... png



我写了sepearte gists,对齐文本diff软件中的行,以确保我做了所有的事情。



我不认为我错过了任何我不知道为什么它在最后一行崩溃 p>

任何ObjC / CG人都可以看到任何错误的类型定义或者我错过的东西(例如ObjC代码使用复合语句我不确定我理解/在端口正确的翻译它们)。

一些小时然后张贴这个我马上意识到它哈哈



在选择器中套错字!我有 writeTofile:atomically 而不是 writeToFile:atomically



<如果有人想测试这个,这是一个简单的Firefox插件测试用例。
$ b $ ol
  • 安装一个插件,允许从github安装插件从这里回购: https://addons.mozilla.org/ en-US / firefox / addon / github-extension-installer /
  • 转到提交这个分支的工作: https://github.com/Noitidart/NativeShot/tree/f5f2e8606d3c5c657e901239d3ceb8c8c79a4494
  • 然后点击添加到Firefox按钮在右下角的下载邮编按钮之下
  • 点击工具栏上的按钮图标,添加到Firefox中,如下图所示: http:// i.imgur.com/n7lSxje.png

  • 检查桌面,你现在有一个单一的PNG文件,所有的显示器的截图,巨大的道具@KenThomas!


  • I ported some objective-c/CoreGraphics code that takes a screenshot of multiple monitors but it's not working. The jsctypes guys won't be able to help because the section is just me answering questions lol

    The objc/cg code is from here: https://stackoverflow.com/a/28247749/1828637

    My jsctypes type/struct/declares are here: https://github.com/Noitidart/NativeShot/blob/mac-troubleshooting/modules/ostypes_mac.jsm

    The jsctypes port is here: https://github.com/Noitidart/NativeShot/blob/mac-troubleshooting/modules/workers/MainWorker.js#L443-656

    And the last line is line 643 which causes the crash:

    var rez_writeToFile = ostypes.API('objc_msgSend')(data, ostypes.HELPER.sel('writeTofile:atomically:'), myNSStrings.get(OS.Path.join(OS.Constants.Path.desktopDir, 'full_ss.png')), ostypes.CONST.YES);
    

    This coincides with the objectivec of

    [data writeToFile:@"/tmp/screenshot.png" atomically:YES];
    

    except i changed path to ...desktop/...png

    I wrote to sepearte gists, to align the lines in text diff software to make sure I did everything.

    I dont think i missed anything i dont know why it crashes on that final line

    Do any of the ObjC/CG people see any type definition that is wrong or something that I missed (for example the ObjC code uses compound statments I'm not sure I understood/translated them correctly in the port).

    解决方案

    Wowww so after struggling for like some hours then posting this I realize it right away haha

    Casing typo in selector!! I had writeTofile:atomically instead of writeToFile:atomically!

    If anyone would like to test this out, it's a simple firefox addon test case.

    1. Install an addon that allows installing addons from github repos from here: https://addons.mozilla.org/en-US/firefox/addon/github-extension-installer/
    2. Go to commit on this branch that works here: https://github.com/Noitidart/NativeShot/tree/f5f2e8606d3c5c657e901239d3ceb8c8c79a4494
    3. Then click the "Add to Firefox" button at bottom right, below the "Download Zip" button
    4. Click on the toolbar button icon that gets added to firefox, as seen in this screenshot: http://i.imgur.com/n7lSxje.png
    5. Check desktop you now have a single png file with a screenshot of all the monitors, huge props to @KenThomas!

    这篇关于将OSX Obj-C / CG截屏代码移植到js-ctypes - 在最后一行崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆