当调用 NSOpenPanel 的 runModal 时,我的应用程序将无法正确终止

发布于 2024-10-15 22:56:05 字数 1711 浏览 5 评论 0原文

我正在编写一个简单的 Cocoa 应用程序,没有核心数据或多文档支持。在 Mac Pro、OS X 10.6.6、Xcode 3.2.3 上运行。

我已将应用程序简化为 AppDelegate 类中的以下代码:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{
    NSOpenPanel *openPanel = [NSOpenPanel openPanel];
    [openPanel runModal];

    return;
}

在调试器中,我将运行我的应用程序。正如预期的那样,将会出现一个不太有用的 OpenPanel。我将单击“取消”,它就会消失。这一切都在预料之中。当我单击 [Command + Q] 退出应用程序时,UI 将消失,但调试器将指示应用程序仍在运行(控制台输出也是如此)。

根据我正在阅读的所有信息,我不需要做任何其他事情就可以使其正常运行。我已经下载了几个有关“打开面板”用法的示例,但大多数都使用已弃用打开模式的方法,以提供附加信息作为参数。 FWIW,我尝试了这些方法,但仍然看到相同的结果。

最后一项,当“打开”对话框出现时,我立即看到一个消息框,询问我是否希望我的应用程序接收传入连接。对话框很快消失。我不知道这是否是我的问题的一部分。 [更新 - 这涉及我的防火墙被打开的情况。]

是的,我对 Objective C 相当陌生,但对一般编程并不熟悉。任何智慧之言都将不胜感激!

2011.02.07 - 更新:

我已经逐行运行了调试器,没有发生任何事件。控制台窗口中没有任何程序故障的迹象。

我说调试器在 [Command + Q] 之后仍然处于活动状态,因为“停止进程”工具栏按钮仍然处于启用状态,“中断”按钮也是如此。此外,控制台表明,在我告诉应用程序终止(通过菜单或键盘命令)后,它仍在运行。以下是从运行开始到退出应用程序后的完整控制台输出。

Program loaded.
run
[Switching to process 62370]
Running...

活动监视器(系统工具)将显示我的应用程序正在终止(不再显示为进程),但调试器仍然不会转换到“编辑”模式 - 如果我告诉 Xcode 再次运行调试器,它会询问我是否是单击“确定”停止当前调试会话。如果我在 Windows 中,我会开始寻找后台线程来保持进程处于活动状态,但据我所知,NSOpenPanel 不应该做类似的事情。

我进一步简化了程序,只不过是创建一个全新的 Cocoa 应用程序并插入上面的代码片段 - 没有对模板项目进行任何其他添加或以任何方式进行更新。

最后,当应用程序在 Leaks Performance Tool 下运行时,在创建面板但从未使用面板时一切都运行良好。但是,当创建并实际使用时,在运行结束时,我将在工具“insufficient task_for_pid特权(leakagent64)”中收到以下消息。谷歌搜索这很痛苦。如果我没看错的话,调试器没有足够的权限来完全杀死目标进程???现在这听起来很愚蠢但是......这没有意义!

另一个更新 - 我刚刚下载并运行了 FunHouse,它是也使用 NSOpenPanel 的 SDK 示例应用程序之一。嗯,我不觉得很特别吗?它表现出完全相同的行为。因此,我得出的结论是,要么苹果的代码中有错误,要么我的机器很特殊并且很混乱,最后,这不是我的代码有问题。这是最好的部分。明天,我将使用朋友的 Mac,看看他的机器上是否出现相同的行为。

这实在是太奇怪了。

I'm writing a simple Cocoa Application, no core data or multiple document support. Running on a Mac Pro, OS X 10.6.6, Xcode 3.2.3.

I have reduced my application to the following code in my AppDelegate class:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{
    NSOpenPanel *openPanel = [NSOpenPanel openPanel];
    [openPanel runModal];

    return;
}

From within the debugger, I will run my application. As expected a somewhat not-to-useful OpenPanel will appear. I will click Cancel and it will disappear. All this is as expected. When I click [Command + Q] to Quit the application, the UI will go away but the debugger will indicate that the application is still running (as does the console output).

Based upon all the information I'm reading, I should not have to do anything else in order for this to run right. I've downloaded several examples on the Open Panel's usage but most use the deprecated methods of opening modal giving additional information as parameters. FWIW, I tried those methods and am still seeing the same result.

One last item, when the Open dialog appears, just for an instant I see a message box asking me something to the extent if I want my application to receive incoming connections. The dialog quickly disappears. I don't know if that is part of my problem or not. [Update - this deals with my Firewall being turned on.]

Yes, I'm fairly new at Objective C but not at programming in general. Any words of wisdom is greatly appreciated!

2011.02.07 - Update:

I have walked the debugger line by line without incident. There is no indication of any program failure in the console window.

I say that the debugger is still active after [Command + Q] because the Stop Process toolbar button is still enabled as is the Break button. Further the console indicates that after I tell the application to terminate (either via the menu or key command) that it is still running. The following is the Complete console output from start of run to after I Quit the application.

Program loaded.
run
[Switching to process 62370]
Running...

The Activity Monitor (system tool) will show my application terminating (no longer shows up as a process) but the Debugger will still not transition to "edit" mode - if I tell Xcode to run the debugger again, it will ask me if it's OK to Stop the current debugging session. If I was in Windows I would start looking for background threads keeping the process alive but as far as I know, NSOpenPanel should not be doing something like that.

I have further simplified the program to nothing more than creating a brand new Cocoa application and inserting the code snippet above - no other additions to the template project or updates in any way.

And lastly, when the application is run under the Leaks Performance Tool, everything runs fine when the panel is created but never used. When created and actually used though, at the end of the run I will get the following message in the tool "insufficient task_for_pid privileges (leakagent64)". Googling this hurts. If I read it right, the debugger does not have sufficient permissions to fully kill the target process ??? Now that sounds stupid but ... It does not make sense!

Another update - I just downloaded and ran FunHouse, one of the SDK sample applications that also uses NSOpenPanel. Well don't I feel special. It exhibits the same exact behavior. So from this I conclude either Apple has a bug in their code, my machine is special and messed up, and finally, it is Not my code that is at fault. That being the best part. Tomorrow, I will use a friends Mac and see if the same behavior is exhibited on his box.

This is just too weird.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒浓于脸红 2024-10-22 22:56:05

我重新启动了我的盒子,让它开始工作,发现它非常有用!我假设这是固定的,与工作时相比,与家里的任何其他连接设备无关。

如果它在家里重新出现,那么就是网络/设备问题。感谢大家的意见和建议!非常感谢。

I rebooted my box, took it to work and found it worked like a charm! I will assume this is fixed and has nothing to do with any other connected devices at home as compared to at work.

If it re-exhibits at home, then it is a network/device issue. Thanks all for your inputs and suggestions! Very much appreciated.

因为看清所以看轻 2024-10-22 22:56:05

调试器具体说了什么?您的程序可能崩溃了,因此调试器正在向您显示有关崩溃的信息。

如果您忽略运行“打开”面板的任何尝试怎么办?

What, specifically, does the debugger say? It's possible that your program crashed, so the debugger is showing you information about the crash.

What if you omit any attempt to run an Open panel?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文