【问题标题】:Using RedLaser SDK via MonoTouch crashing as soon as BarcodePickerController shown一旦 BarcodePickerController 显示,通过 MonoTouch 使用 RedLaser SDK 就会崩溃
【发布时间】:2012-04-19 22:22:20
【问题描述】:

我正在使用 Chris Branson 的 RedLaser MonoTouch 绑定和示例: https://github.com/chrisbranson/RedLaserSample

首先,为了帮助那些在这个示例项目中也遇到问题的人,我必须更新 makefile 以构建 RedLaser.dll MonoTouch 绑定和示例 MonoDevelop csproj 以获得实际的应用程序编译。

  • 生成文件
    Chris 提供的 makefile 解压缩了 RedLaser SDK 下载,但 RedLaser 更改了它们的命名约定,因此它不再工作。我对其进行了简化,而是要求用户手动将 libRedLaserSDK.a 文件放入构建目录:

    BTOUCH=/Developer/MonoTouch/usr/bin/btouch
    BUILDVER=build139
    VERSION=3.2.4
    BINDIR=./bin/
    
    all: $(BINDIR)RedLaser.dll
    
    $(BINDIR)libRedLaserSDK.a: 
        @echo "You'll need to obtain a copy of RedLaserDevSDK-$(VERSION).zip from"
        @echo "http://redlaser.com/sdk/index.php"
        @echo Locate the libRedLaserSDK.a file and place within
        @echo $(BINDIR)
        @echo 
        @open http://redlaser.com/sdk/index.php
        @exit 1
    
    $(BINDIR)RedLaser.dll: Makefile AssemblyInfo.cs RedLaser.cs enums.cs $(BINDIR)libRedLaserSDK.a
        $(BTOUCH) --out=$@ -e RedLaser.cs enums.cs AssemblyInfo.cs --link-with=$(BINDIR)libRedLaserSDK.a,libRedLaserSDK.a
    
    clean:
        -rm -rf $(BINDIR)*.dll  
    

    包含 makefile 的目录还应包含文件 redlaser.csenums.csAssemblyInfo.cs(即与 Chris 的相同)。

  • MonoDevelop 项目构建设置
    我认为这停止工作的原因是 MonoDevelop 或 MonoTouch 中的一个错误,以及当它们包含引号时它扩展“附加 mtouch 参数”的方式。 Chris 的原始论点如下所示:

    -cxx -gcc_flags="-framework SystemConfiguration -framework CFNetwork -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework OpenGLES -framework Security -L${ProjectDir}/Lib -lRedLaserSDK -ObjC"  
    

    MonoDevelop 没有正确解析这个,而是在每个选项周围插入引号,用空格分隔。查看构建输出(在“编译为本机代码”下)表明这已扩展为:

    "/Users/tyson/Downloads/chrisbranson-RedLaserSample-1a5545f-1/RedLaserSample/Lib/RedLaser.dll" -debug -nolink -sdk "5.1" -targetver "5.1" --armv7 "-cxx" "-gcc_flags=\"-framework" "SystemConfiguration" "-framework" "CFNetwork" "-framework" "CoreVideo" "-framework" "CoreMedia" "-framework" "AVFoundation" "-framework" "OpenGLES" "-framework" "Security" "-L/Users/tyson/Downloads/chrisbranson-RedLaserSample-1a5545f-1/RedLaserSample/Lib" "-lRedLaserSDK" "-ObjC\""  
    

    解决方案包括在整个 'gcc_flags' 选项周围添加显式引号,手动转义内部引号。例如:

    "-cxx" "-gcc_flags=\"-framework SystemConfiguration -framework CFNetwork -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework OpenGLES -framework Security -L${ProjectDir}/Lib -lRedLaserSDK -ObjC\""  
    

    这正确扩展为:

    "/Users/tyson/Downloads/chrisbranson-RedLaserSample-1a5545f-1/RedLaserSample/Lib/RedLaser.dll" -debug -nolink -sdk "5.1" -targetver "5.1" --armv7 "-cxx" "-gcc_flags=\"-framework SystemConfiguration -framework CFNetwork -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework OpenGLES -framework Security -L/Users/tyson/Downloads/chrisbranson-RedLaserSample-1a5545f-1/RedLaserSample/Lib -lRedLaserSDK -ObjC\""
    

好的,现在我已经编译了它,我尝试在手机上运行它。该应用程序加载正常,并通过RedLaserSDK.CheckReadyStatus() 函数成功调用 RedLaser SDK。但只要我点击扫描按钮(加载BarcodePickerController),它就会崩溃,并在 RedLaser SDK 深处出现本机异常:

terminate called throwing an exception
Native stacktrace:

0   RedLaserSample                      0x0159d62d mono_handle_native_sigsegv + 244
1   RedLaserSample                      0x015b6251 sigabrt_signal_handler + 112
2   libsystem_c.dylib                   0x319b67ed _sigtramp + 48
3   libsystem_c.dylib                   0x319ac20f pthread_kill + 54
4   libsystem_c.dylib                   0x319a529f abort + 94
5   libc++abi.dylib                     0x34fb1f6b abort_message + 46
6   libc++abi.dylib                     0x34faf34d _ZL17default_terminatev + 24
7   libobjc.A.dylib                     0x358e536f _objc_terminate + 170
8   libc++abi.dylib                     0x34faf3c5 _ZL19safe_handler_callerPFvvE + 76
9   libc++abi.dylib                     0x34faf451 _ZdlPv + 0
10  libc++abi.dylib                     0x34fb079f __cxa_throw + 122
11  RedLaserSample                      0x000404a9 _ZN5zxing6qrcode19FinderPatternFinder18selectBestPatternsEv + 172
12  RedLaserSample                      0x000415e9 _ZN5zxing6qrcode19FinderPatternFinder4findERKNS_11DecodeHintsE + 512
13  RedLaserSample                      0x0003a7f7 _ZN5zxing6qrcode8Detector6detectERKNS_11DecodeHintsE + 366
14  RedLaserSample                      0x00046b97 _ZN5zxing6qrcode12QRCodeReader6decodeENS_3RefINS_12BinaryBitmapEEENS_11DecodeHintsE + 130
15  RedLaserSample                      0x0004ec35 _ZN5zxing6Reader6decodeENS_3RefINS_12BinaryBitmapEEE + 240
16  RedLaserSample                      0x00058455 -[FormatReader decode:] + 116
17  RedLaserSample                      0x00013835 -[ZXingDecoder findCodesInBitmap:bytesPerRow:width:height:] + 656
18  RedLaserSample                      0x0005f6af -[BarcodePhotoEngine zxingFindBarcodesInPixmap:] + 222
19  RedLaserSample                      0x00055f25 __38-[BarcodeEngine findBarcodesInPixMap:]_block_invoke_059 + 76
20  libdispatch.dylib                   0x34635c59 _dispatch_call_block_and_release + 12
21  libdispatch.dylib                   0x34637d0f _dispatch_queue_drain + 274
22  libdispatch.dylib                   0x34637b75 _dispatch_queue_invoke$VARIANT$mp + 40
23  libdispatch.dylib                   0x346387e7 _dispatch_worker_thread2 + 210
24  libsystem_c.dylib                   0x31967dfb _pthread_wqthread + 294
25  libsystem_c.dylib                   0x31967cd0 start_wqthread + 8

=================================================================  
Got a SIGABRT while executing native code. This usually indicates  
a fatal error in the mono runtime or one of the native libraries  
used by your application.  
=================================================================

运行非常相似的 RedLaser Xcode 示例项目(即不涉及 MonoTouch,全部为 Objective-c)工作正常。

此外,如果有任何意义,禁用所有条形码扫描类型允许BarcodePickerController 加载并显示相机视图。显然它永远不会检测到条形码。

【问题讨论】:

  • 只是一个想法,您是否尝试过使用 MonoTouch 绑定项目而不是他们的 makefile?以这种方式编译 Objective-C 绑定我总是比较幸运(而且您可以轻松地将其置于源代码管理中)。

标签: c# xamarin.ios barcode barcode-scanner


【解决方案1】:

你提到的崩溃现在是fixed in the bindings

这与 QR 使用 C++ 异常和不正确的链接参数有关。

【讨论】:

  • 谢谢!我现在正在使用 ZBar,但我仍然很好奇是什么原因造成的。我查看了您的提交并在您的上述答案中添加了指向它的链接,只是为了看看更改是什么(并让其他对此感到好奇的人也看到它)。因此,您添加的 NeedsGccExceptionHandling 选项是绑定到可以从绑定函数调用中引发 c++ 异常的库的任何绑定所必需的吗?是否会导致所有函数绑定都包装在 try-catch 中并抛出 CIL 兼容异常?
  • @Tyson:实际上恰恰相反:我将 NeedsGccExceptionHandling 设置为 false。该值当前将使 MonoTouch 将 -lgcc_eh 传递给链接器,这是实际的问题(我们最终会在二进制文件中加载一些异常处理函数,特别是注册捕获处理程序的函数 - 但不是函数处理throw 语句。如果 throw 函数与 catch 函数不匹配,则 throw 函数将找不到任何 catch 处理程序并中止进程。
【解决方案2】:

根据您粘贴的 Makefile,此 RedLaser 绑定使用 MonoTouch 支持的 LinkWith[1] 功能,无需使用任何“附加 mtouch 参数”。

只需从项目选项中的其他 mtouch 参数配置中清除 RedLaser 所需的任何参数,事情就可能会正常构建和工作。

如果没有,请尝试使用来自 https://github.com/xamarin/monotouch-bindings 的 RedLaser 绑定,这可能是最新的?

注意事项:

  1. http://blog.xamarin.com/2011/11/02/monotouch-native-libraries-made-easy/

【讨论】:

  • 哈哈'可能是最新的'-来自 github 页面:“RedLaser 39 分钟前 [RedLaser] 已将 -unsafe 添加到 btouch args,因为现在需要它。[jstedfast]。”谢谢,我现在就去看看。
  • 哦,删除所有“额外的 mtouch 参数”不起作用,我已经尝试过了。
  • 好的,所以我使用链接的 GitHub 存储库中的 makefile 编译了最新的 RedLaser.dll 绑定。没问题。我将它复制到随附的示例项目的根目录中,检查了“其他 mtouch 参数”并确认不再需要它们(它是空的)。一切都编译得很好。好的!加载到我的手机上并运行 - 到了第一页,它显示了 RedLaserSDK 的正确 Eval 版本,但是一旦我点击扫描,我就会得到与上面完全相同的 SIGABRT 崩溃。我正在切换到 ZBar... 完成后我会将绑定上传到某个地方。
  • 在阅读了新的“LinkWith”功能后,我注意到 libRedLaserSDK 和所有相关框架都已链接,但没有指定 RedLaser XCode 示例项目链接的“libiconv.dylib”链接。我按照“LinkerFlags”下的docs.xamarin.com/ios/advanced_topics/binding_objective-c_types/… 说明并添加了LinkerFlags =“-liconv”。它没有帮助,但我想知道如果没有这些说明,这个库是如何链接的?
  • -liconv 可能不需要,这就是它链接正常的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-04-15
  • 2018-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多