我的记忆力有问题。
我有一个C++库(来自Eyescale的均衡器),它们使用遍历访问者模式来允许您向它们的类添加新功能。
我终于弄清楚了它是如何工作的,并且我有一个Visitor,它只返回其中一个对象的属性。(因为我不知道它们是如何分配的)。
所以。
我的小代码做到了这一点:
VisitorResult AGLContextVisitor::visit( Channel* channel )
{
// Search through Nodes, Pipes until we get to the right window.
// Add some code to make sure we find the right one?
// Not executing the following code as C++ in gdb?
eq::Window* w = channel->getWindow();
OSWindow* osw = w->getOSWindow();
AGLWindow* aw = (AGLWindow *)osw;
AGLContext agl_ctx = aw->getAGLContext();
this->setContext(agl_ctx);
return TRAVERSE_PRUNE;
} 这就是问题所在。
eq::Window* w = channel->getWindow();
(gdb) print w
0x0 但如果我这样做:
(gdb) set objc-non-blocking-mode off
(gdb) print w=channel->getWindow()
0x300effb9 //诚实的内存位置,并将w设置为在XCode的调试器窗口中验证。
它对osw做了同样的事情。
我还是不明白。为什么某些东西可以在(gdb)中工作,但在代码中却不能工作?
该文件完全是一个cpp文件,但它似乎是在objc++中运行的,因为我需要关闭阻止。
救命!?我觉得我在这里遗漏了一些内存管理的基本东西,无论是使用C++还是Obj-C。
编辑
channel->getWindow()应该这样做:
/** @return the parent window. @version 1.0 */
Window* getWindow() { return _window; }如果我从一个只支持C++的应用程序中运行代码,它也可以很好地执行。
编辑
不..。我试着创建一个简单的独立程序,因为我厌倦了将它作为插件运行。调试起来很麻烦。
而且,它也不能在C++程序中运行。所以我真的不知道我做错了什么。
谢谢,
--斯蒂芬·芙拉尼
发布于 2010-05-14 22:13:22
我想我应该回答并结束这个问题。
我使用的方法完全是线程不安全的。我是跨线程调用的,Carbon/Cocoa,C++/ObjC。
不用说,永远不要这么做!我吃了苦头才学会的。
-Stephen
https://stackoverflow.com/questions/2200207
复制相似问题