程序不正确终止 [英] Program Doesn't Terminate Correctly

查看:113
本文介绍了程序不正确终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个计算机视觉应用程序(C ++和OpenCV)。我使用wxWidgets创建一个GUI - 这是非常简单;

I'm writing a computer vision app (C++ and OpenCV). I am creating a GUI for it with wxWidgets - this is very simple; a button-press event calls the tracker app to begin.

我的终止应用程序的调用(即点击关闭按钮)如下:

My call to terminate the app (i.e. on clicking to close button) is as follows:

// Exiting the App
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    // true is to force the frame to close
    Close(true);
}

这通常适用于更为简单的GUI应用程序。然而,在这种情况下,框架消失了,在任务管理器中,进程似乎继续运行和保持内存。这是非常讨厌,因为如果我运行或调试应用程序,并稍后进行一些更改,并尝试再次运行,而无需事先手动终止该过程,编译器抛出一个链接错误,因为.exe是

This usually works with more trivial GUI apps. However, on this occasion, the frame disappears yet, in the task manager, the process seems to continue running and holding memory. It's very annoying because if I run or debug the application and later make some changes and try to run again, without manually terminating the process beforehand, the compiler throws a link error because the .exe is

没有找到或未建立的最后一个增量链接。$ b

not found or not built by the last incremental link.


力出口(1);在onQuit方法,但它会导致应用程序崩溃。

Tried inserting a brute force exit(1); in the onQuit method but it causes the app to crash.

我不知道是什么..当运行没有GUI,应用程序运行和终止罚款尽管它的调用方式与main()函数略有不同,而不是调用抽象基类的按钮事件处理程序)。

I'm not sure what it is.. when running without the GUI, the app runs and terminates fine (albeit it is called slightly differently - from the main() function instead of from a button-press event handler which calls an abstract base class).

是因为一个类是用全局范围声明的?在一个文件中,我有一个类的实例在任何类方法之外声明的?或许wxWidgets无法处理这个问题?

Is it possible that it is because a class is being declared with global scope? As in, in one file I have an instance of a class declared outside of any class method? Perhaps wxWidgets can't handle this?

澄清

我关闭是一个顶级框架。在没有调用计算机视觉方法时,我没有遇到完全相同的GUI代码的问题。

The frame I'm closing is a top level frame. I had no problems with the exact same GUI code when it does not call the computer vision methods.

我没有特别编码任何多线程,我得到一个错误,说错误:无法初始化OLE。要解决这个问题,我不得不将wxuse_DRAG_AND_DROP,wxUSE_CLIPBOARD,wxUSE_OLE和wxUSE_OLE_AUTOMATION设置为0(而不是1),然后重新编译wxWidgets。

I haven't specifically coded any multi-threading but to begin with, I was getting an error that said "Error: Cannot initialize OLE". To fix this, I had to set wxUSE_DRAG_AND_DROP, wxUSE_CLIPBOARD, wxUSE_OLE and wxUSE_OLE_AUTOMATION to 0 (instead of 1) and then (re)compile wxWidgets.

某些类型的线程继续与HighGUI与WxWidgets不一致?有没有人遇到类似的问题?

Just wondering, is there some kind of threading going on with HighGUI that is inconsistent with WxWidgets? Has anybody else encountered similar problems?

推荐答案

感谢所有的帮助,看起来很明显现在,但当时无法弄清楚!

Thanks for all the help, I have solved the problem. Seems fairly obvious now but couldn't figure it out at the time!

最初,我的电脑视觉应用程序是从一个主要的函数。但是,使用新的GUI代码,没有必要一个main,所以我用一个shell类替换原来的main。

Originally, my computer vision app was called from a main function. However, with the new GUI code there is no need for a main so I replaced the original main with a shell class.

虽然我一直小心释放分配的内存我的计算机视觉类的方法我没有这么仔细原来的主要功能,因为一旦该功能结束,以前使用的所有内存将清除由程序的正常退出。

Though I had been careful to free allocated memory within the methods of my computer vision classes I had not been so careful with the original main function because once that function ended, all memory previously in use would be cleared up by the program's regular exiting.

与新的GUI代码的区别是,当shell类完成时 - 程序仍在运行。线索是,即使计算机视觉应用程序已经结束,我的网络摄像头上的蓝色灯仍然闪亮。

The difference with the new GUI code is that when the shell class is finished - the program is still running. The clue was in the fact that even when the computer vision app had ended, the blue light on my webcam was still shining.

*一定要调用cvReleaseCapture (& capture);释放该线程并释放硬件*

这篇关于程序不正确终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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