将OSX Obj-C / CG截屏代码移植到js-ctypes - 在最后一行崩溃 [英] Ported OSX Obj-C/CG Screenshot Code to js-ctypes - crash on final line
问题描述
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
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.
- Here is objc/cg: https://gist.github.com/Noitidart/8affcd8bee60d22dcb52
- and here is jsctypes: https://gist.github.com/Noitidart/3d4a4e8df625dbea8cc1
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.
- Install an addon that allows installing addons from github repos from here: https://addons.mozilla.org/en-US/firefox/addon/github-extension-installer/
- Go to commit on this branch that works here: https://github.com/Noitidart/NativeShot/tree/f5f2e8606d3c5c657e901239d3ceb8c8c79a4494
- Then click the "Add to Firefox" button at bottom right, below the "Download Zip" button
- Click on the toolbar button icon that gets added to firefox, as seen in this screenshot: http://i.imgur.com/n7lSxje.png
- 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屋!