绑定的问题:调用基础方法绑定类调用覆盖方法。导致无限递归 [英] Issues with Bindings: Calling base method on binding class calls override method. Leads to infinite recursion

查看:448
本文介绍了绑定的问题:调用基础方法绑定类调用覆盖方法。导致无限递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用Cordova的MonoTouch项目。我为Cordova创建了一个绑定(基于Scott Blomquist创建的绑定 a>)。



我已经能够相当好地实例化类,而不会失败。当我尝试延长他们,但我遇到了问题。例如,如果我只是尝试扩展CDVViewController,甚至没有重写任何东西,当我们得到实例化这个扩展类的代码时,系统会静静地退出,没有错误消息和以下退出行。

 程序Mono已退出代码0(0x0)。 
程序'[5600] *** .vshost.exe:Managed(v4.0.30319)'已退出,代码为-1(0xffffffff)。

这是我想要实例化的类

  public class WebViewController:CDVViewController 
{
}

这里是它的绑定

  [BaseType(typeof(UIViewController))] 
interface CDVViewController {
[Export(webView)]
UIWebView WebView {get;组; }

[Export(pluginObjects)]
NSMutableDictionary PluginObjects {get; }

[Export(pluginsMap)]
NSDictionary PluginsMap {get; }

[Export(settings)]
NSDictionary设置{get; }

[Export(whitelist)]
CDVWhitelist白名单{get; }

[Export(loadFromString)]
bool LoadFromString {get; }

[Export(useSplashScreen)]
bool UseSplashScreen {get;组; }

[Export(activityView)]
UIActivityIndi​​catorView ActivityView {get; }

[Export(imageView)]
UIImageView ImageView {get; }

[Export(wwwFolderName)]
string WwwFolderName {get;组; }

[Export(startPage)]
string StartPage {get;组; }

[Export(commandQueue)]
NSObject CommandQueue {get;组; }

[Export(commandDelegate)]
NSObject CommandDelegate {get;组; }

[Export(userAgent)]
string UserAgent {get; }

[Export(printMultitaskingInfo)]
void PrintMultitaskingInfo();

[Export(createGapView)]
void CreateGapView();

[Export(newCordovaViewWithFrame:)]
UIWebView NewCordovaView(RectangleF bounds);

[Export(javascriptAlert:)]
void JavascriptAlert(string text);

[Export(appURLScheme)]
string AppUrlScheme();

[Export(parseInterfaceOrientations:)]
NSArray ParseInterfaceOrientations(NSArray orientation);

[Export(supportsOrientation:)]
bool SupportsOrientation(UIInterfaceOrientation orientation);

[Export(getCommandInstance:)]
NSObject GetCommandInstance(string pluginName);

[Export(registerPlugin:withClassName:)]
void RegisterPluginWithClassName(CDVPlugin plugin,string className);

[Export(URLisAllowed:)]
bool UrlIsAllowed(NSUrl url);

[Static] [Export(getBundlePlist:)]
NSDictionary GetBundlePlist(string plistName);

[静态] [导出(applicationDocumentsDirectory)]
string ApplicationDocumentsDirectory();

//以下方法和属性来自UIWebViewDelegate,但是我们不能做多重继承
[Export(webView:shouldStartLoadWithRequest:navigationType:)]
bool ShouldStartLoad (UIWebView webView,NSUrlRequest request,UIWebViewNavigationType navigationType);
}

CDVViewController.h 可用此处



任何帮助



更新#1
这似乎是由细分错误导致的。对于任何其他遇到这种情况,如果你去Mac和检查日志,你可能会发现同样的。你可以打开终端,输入 tail -f /var/log/system.log ,显然这是模拟器的日志。 p>

在我的日志中,我发现了以下内容。 *** 用于修改应用程序名称。

  16:51:16 macmini1 com.apple.launchd.peruser.55385368 [409](UIKitApplication:com。***。*** [0x5ef3] [14219]):作业似乎已崩溃:分段错误:11 
Mar 28 16:51:16 macmini1 SpringBoard [516]:应用程序'***'异常退出信号11:分段错误:11
Mar 28 16:51:16 macmini1 ReportCrash [14132]:保存崩溃report for *** [14219] version ??? (???)到/Users/jstarke/Library/Logs/DiagnosticReports/***_2013-03-28-165116_macmini1.crash
Mar 28 16:51:16 macmini1 ReportCrash [14132]:删除过多的日志: file://localhost/Users/jstarke/Library/Logs/DiagnosticReports/***_2013-03-28-135722_macmini1.crash

更新#2
我发现上面提到的崩溃报告。这是最新的崩溃报告信息,包括崩溃的线程

 进程:*** [29880] 
路径: / Users / * / Library / Application Support / iPhone Simulator / * / ***。app / ***
标识符:***
版本: (???)
代码类型:X86(原生)
父进程:launchd [409]

日期/时间:2013-03-29 11:44:48.882 - 0700
OS版本:Mac OS X Server 10.7.5(11G63)
报告版本:9

崩溃的线程:0调度队列:com.apple.main-thread

异常类型:EXC_BAD_ACCESS(SIGSEGV)
异常代码:KERN_PROTECTION_FAILURE在0x00000000bf7fff7c

VM区域附近0xbf7fff7c:
堆栈00000000b050b000-00000000b052c000 [132K] rw- / rwx SM = COW
- >堆栈00000000bc000000-00000000bf800000 [56.0M] --- / rwx SM = NUL
堆栈00000000bf800000-00000000c0000000 [8192K] rw- / rwx SM = COW

应用特定信息:
iPhone模拟器358.4,iPhone OS 6.0(iPhone / 10A403)


线程0崩溃::分派队列:com.apple.main线程
0 libsystem_c.dylib
0x954d458c szone_malloc_should_clear + 12
1 libsystem_c.dylib
0x954d566b szone_malloc + 24
2 libsystem_c.dylib
0x9550b962 malloc_zone_malloc + 77
3 libsystem_c.dylib
0x9550c882 malloc + 50
4 libobjc.A.dylib
0x041985c9 class_copyProtocolList + 157
5 CoreFoundation
0x03f72962 __methodDescriptionForSelector + 178
6 CoreFoundation
0x03fe65a3 - [NSObject NSObject)methodSignatureForSelector:] + 51
7 ***
0x00254352 monotouch_trampoline + 82
8
0x16c4ab0b 0 + 381987595
9
0x16c7428c 0 + 382157452
10
0x16c743dc 0 + 382157788
11 ***
0x0004cf22 mono_jit_runtime_invoke + 722
12 ***
0x001b03fe mono_runtime_invoke + 126
13 ***
0x00255166 monotouch_trampoline + 3686

行8 - 13重复大量次数(无其他信息)

506?
0x16c4ab0b 0 + 381987595
507?
0x16c7428c 0 + 382157452
508?
0x16c743dc 0 + 382157788
509 ***
0x0004cf22 mono_jit_runtime_invoke + 722
510 ***
0x001b03fe mono_runtime_invoke + 126
511 ***
0x00255166 monotouch_trampoline + 3686

更新#3 努力获得一些更多的信息,我决定覆盖我的本地WebViewController内的CDVViewController中的所有方法,然后从每个方法的基本等效值返回值,并设置一个断点上的方法,并放一个控制台。 WriteLine说我们输入并退出了每个方法。



令我惊讶的是,在更新#2 中有许多重复的原因当调用 WebViewController.ShouldAutoRotateToInterfaceOrientation 时,我们调用基类 CDVViewController.ShouldAutoRotateToInterfaceOrientation ,这显然依次调用 WebViewController.ShouldAutoRotateToInterfaceOrientation ,等等。



查看Cordova版本的源代码我正在使用(这里), shouldAutorotateToInterfaceOrientation:会调用 supportsOrientation :,它将从 NSArray 返回。



我看不到任何原因为什么 CDVViewController.ShouldAutoRotateToInterfaceOrientation 应该调用 WebViewController。 ShouldAutoRotateToInterfaceOrientation

解决方案

如果任何人遇到类似的问题,与绑定,我设法得到这个工作感谢Rolf Bjarne Kvinge的建议(绑定问题:扩展类引导方法调用自己?



结果是我使用的标志理解它做了什么)是怪这个。当使用 btouch 生成DLL时, -e 标志生成不能子类化的较小类



删除此操作可能会解决您的问题,就像它为我做的那样。


I'm working on a MonoTouch project that uses Cordova. I created a binding for Cordova (based on the one created by Scott Blomquist).

I have been able to instantiate the classes fairly well without fail. When I try to extend them however, I run into issues. For example, if I merely try extend the CDVViewController, without even overriding anything, when we get to the code that instantiates this extended class, the system quietly exits with no error messages, and the following exit lines.

The program 'Mono' has exited with code 0 (0x0).
The program '[5600] ***.vshost.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).

Here is the class I'm trying to instantiate

public class WebViewController : CDVViewController
{
}

And here's the binding behind it

[BaseType (typeof (UIViewController))]
interface CDVViewController {
    [Export ("webView")]
    UIWebView WebView { get; set; }

    [Export ("pluginObjects")]
    NSMutableDictionary PluginObjects { get; }

    [Export ("pluginsMap")]
    NSDictionary PluginsMap { get; }

    [Export ("settings")]
    NSDictionary Settings { get; }

    [Export ("whitelist")]
    CDVWhitelist Whitelist { get; }

    [Export ("loadFromString")]
    bool LoadFromString { get; }

    [Export ("useSplashScreen")]
    bool UseSplashScreen { get; set; }

    [Export ("activityView")]
    UIActivityIndicatorView ActivityView { get; }

    [Export ("imageView")]
    UIImageView ImageView { get; }

    [Export ("wwwFolderName")]
    string WwwFolderName { get; set; }

    [Export ("startPage")]
    string StartPage { get; set; }

    [Export ("commandQueue")]
    NSObject CommandQueue { get; set; }

    [Export ("commandDelegate")]
    NSObject CommandDelegate { get; set; }

    [Export ("userAgent")]
    string UserAgent { get; }

    [Export ("printMultitaskingInfo")]
    void PrintMultitaskingInfo ();

    [Export ("createGapView")]
    void CreateGapView ();

    [Export ("newCordovaViewWithFrame:")]
    UIWebView NewCordovaView(RectangleF bounds);

    [Export ("javascriptAlert:")]
    void JavascriptAlert (string text);

    [Export ("appURLScheme")]
    string AppUrlScheme ();

    [Export ("parseInterfaceOrientations:")]
    NSArray ParseInterfaceOrientations (NSArray orientations);

    [Export ("supportsOrientation:")]
    bool SupportsOrientation (UIInterfaceOrientation orientations);

    [Export ("getCommandInstance:")]
    NSObject GetCommandInstance (string pluginName);

    [Export ("registerPlugin:withClassName:")]
    void RegisterPluginWithClassName (CDVPlugin plugin, string className);

    [Export ("URLisAllowed:")]
    bool UrlIsAllowed (NSUrl url);

    [Static] [Export ("getBundlePlist:")]
    NSDictionary GetBundlePlist (string plistName);

    [Static] [Export ("applicationDocumentsDirectory")]
    string ApplicationDocumentsDirectory ();

    // The following methods and properties come from UIWebViewDelegate, but we can't do multiple inheritance
    [Export ("webView:shouldStartLoadWithRequest:navigationType:")]
    bool ShouldStartLoad (UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType);
}

The CDVViewController.h that I build the binding for is available here

Any help that anyone can offer would be greatly appreciated.

Update #1 This appears to have been caused by a segmentation fault. For anyone else experiencing this, if you go onto the Mac and check the log, you will likely find the same. You can do this by opening the terminal, and typing in tail -f /var/log/system.log as apparently this is where the logs for the simulator go.

In my log, I found the following. *** is used for redacting the application name.

Mar 28 16:51:16 macmini1 com.apple.launchd.peruser.55385368[409] (UIKitApplication:com.***.***[0x5ef3][14219]): Job appears to have crashed: Segmentation fault: 11
Mar 28 16:51:16 macmini1 SpringBoard[516]: Application '***' exited abnormally with signal 11: Segmentation fault: 11
Mar 28 16:51:16 macmini1 ReportCrash[14132]: Saved crash report for ***[14219] version ??? (???) to /Users/jstarke/Library/Logs/DiagnosticReports/***_2013-03-28-165116_macmini1.crash
Mar 28 16:51:16 macmini1 ReportCrash[14132]: Removing excessive log: file://localhost/Users/jstarke/Library/Logs/DiagnosticReports/***_2013-03-28-135722_macmini1.crash

Update #2 I found the crash reports mentioned above. Here is the latest crash report information, including the crashed thread

Process:         *** [29880]
Path:            /Users/*/Library/Application Support/iPhone Simulator/*/***.app/***
Identifier:      ***
Version:         ??? (???)
Code Type:       X86 (Native)
Parent Process:  launchd [409]

Date/Time:       2013-03-29 11:44:48.882 -0700
OS Version:      Mac OS X Server 10.7.5 (11G63)
Report Version:  9

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000bf7fff7c

VM Regions Near 0xbf7fff7c:
    Stack                  00000000b050b000-00000000b052c000 [  132K] rw-/rwx SM=COW  
--> Stack                  00000000bc000000-00000000bf800000 [ 56.0M] ---/rwx SM=NUL  
    Stack                  00000000bf800000-00000000c0000000 [ 8192K] rw-/rwx SM=COW  

Application Specific Information:
iPhone Simulator 358.4, iPhone OS 6.0 (iPhone/10A403)


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_c.dylib             
0x954d458c szone_malloc_should_clear + 12
1   libsystem_c.dylib             
0x954d566b szone_malloc + 24
2   libsystem_c.dylib             
0x9550b962 malloc_zone_malloc + 77
3   libsystem_c.dylib             
0x9550c882 malloc + 50
4   libobjc.A.dylib               
0x041985c9 class_copyProtocolList + 157
5   CoreFoundation                
0x03f72962 __methodDescriptionForSelector + 178
6   CoreFoundation                
0x03fe65a3 -[NSObject(NSObject) methodSignatureForSelector:] + 51
7   ***                  
0x00254352 monotouch_trampoline + 82
8   ???                           
0x16c4ab0b 0 + 381987595
9   ???                           
0x16c7428c 0 + 382157452
10  ???                           
0x16c743dc 0 + 382157788
11  ***                  
0x0004cf22 mono_jit_runtime_invoke + 722
12  ***                  
0x001b03fe mono_runtime_invoke + 126
13  ***                  
0x00255166 monotouch_trampoline + 3686

Lines 8 - 13 repeat a large number of times (no additional information)

506 ???                           
0x16c4ab0b 0 + 381987595
507 ???                           
0x16c7428c 0 + 382157452
508 ???                           
0x16c743dc 0 + 382157788
509 ***
0x0004cf22 mono_jit_runtime_invoke + 722
510 ***                  
0x001b03fe mono_runtime_invoke + 126
511 ***                  
0x00255166 monotouch_trampoline + 3686

Update #3 In an effort to get some more information, I decided to override all of the methods in the CDVViewController within my local WebViewController, and then return the value from the base equivalent of each method, and set a breakpoint on the method, and put a Console.WriteLine saying that we entered and exited each method.

To my surprise, the reason for the many many duplications in Update #2 has to do with the fact that when WebViewController.ShouldAutoRotateToInterfaceOrientation is called, we call the base class CDVViewController.ShouldAutoRotateToInterfaceOrientation, which apparently in turn calls WebViewController.ShouldAutoRotateToInterfaceOrientation, and so on.

Looking at the source code for the version of Cordova I'm using (here), shouldAutorotateToInterfaceOrientation: would call supportsOrientation:, which would return from an NSArray.

I can't see any reason why CDVViewController.ShouldAutoRotateToInterfaceOrientation should ever call WebViewController.ShouldAutoRotateToInterfaceOrientation. Does anyone in the Xamarin or Cordova community have any idea?

解决方案

If anyone else is experiencing a similar issue relating to Bindings, I managed to get this working thanks to the advice of Rolf Bjarne Kvinge (Binding issues: extending a class leads method calling itself?)

It turns out that a flag that I was using (without really understanding what it did) was to blame for this. When generating the DLL using btouch the -e flag Generates smaller classes that can not be subclassed.

Removing this will likely solve your problem, like it did for me.

这篇关于绑定的问题:调用基础方法绑定类调用覆盖方法。导致无限递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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