OpenGL / Carbon / Cocoa内存管理自动释放问题

时间:2010-05-14 14:58:33

标签: c++ objective-c cocoa memory opengl

Hoooboy,

我还有另一个内存问题。

我正在用C ++创建一个Carbon(AGL)窗口,它告诉我,我autorelease没有池就可以了。

呃......什么?

我认为Carbon存在于NSAutoreleasePool ...

之外

当我致电glEnable(GL_TEXTURE_2D)做某些事情时,它会给我一个EXC_BAD_ACCESS警告 - 但是如果AGL窗口永远不会得到release,那么它不应该存在吗?在set objc-non-blocking-mode设置(gdb)并不能解决问题。

所以我想我的问题是用CARBON / COCOA / NSAutoreleasePool做什么?

而且...... Objective-C ++有什么资源吗?因为这样的垃圾一直在发生在我身上。

谢谢,

-Stephen

---代码---

测试绘制功能

void Channel::frameDraw( const uint32_t frameID)
{
    eq::Channel::frameDraw( frameID );
            getWindow()->makeCurrent(false);
    glEnable(GL_TEXTURE_2D); // Throws Error Here
}

Make Current(以下代码来自Equalizer API,即LGPL Eyescale)

void Window::makeCurrent( const bool useCache ) const
{
    if( useCache && getPipe()->isCurrent( this ))
        return;

    _osWindow->makeCurrent();
}

void AGLWindow::makeCurrent() const
{
    aglSetCurrentContext( _aglContext );
    AGLWindowIF::makeCurrent();

    if( _aglContext )
    {
        EQ_GL_ERROR( "After aglSetCurrentContext" );
    }
}
当我单步执行时,

_aglContext是一个有效的内存位置(即非NULL)。

-S!

---错误---

859 2958110720 //Users/slate/Documents/equalizer/XCode/../lib/client/aglWindow.cpp:367   278 Created AGL context 0x4867200 shared with 0
*** __NSAutoreleaseNoPool(): Object 0x1fc4a950 of class NSCarbonWindowContentView autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1fc4b120 of class NSCFArray autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1f410f50 of class NSMutableParagraphStyle autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x45063f0 of class NSCFDictionary autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x2f2ed50 of class NSPathStore2 autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x44bf380 of class NSCFData autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0xa026cb08 of class NSCFString autoreleased with no pool in place - just leaking
etc...

--- STACK ---

#0  0x9252d3f1 in __NSAutoreleaseNoPool ()
#1  0x9243a794 in _CFAutoreleasePoolAddObject ()
#2  0x9243a4aa in -[NSObject(NSObject) autorelease] ()
#3  0x9372d023 in -[NSCarbonWindow initWithCarbonWindowRef:takingOwnership:disableOrdering:] ()
#4  0x9345bdee in _cocoaAppApplicationEventHandler ()
#5  0x920f00a9 in DispatchEventToHandlers ()
#6  0x920ef370 in SendEventToEventTargetInternal ()
#7  0x920ef1cf in SendEventToEventTargetWithOptions ()
#8  0x92114e44 in SendShowHideEvent ()
#9  0x921148b1 in _ShowHideWindows ()
#10 0x92177341 in ShowWindow ()
#11 0x2a01fab0 in eq::AGLWindow::configInitAGLWindow (this=0x400d260) at /Users/slate/Documents/equalizer/XCode/../lib/client/aglWindow.cpp:541
#12 0x2a01f380 in eq::AGLWindow::configInitAGLDrawable (this=0x400d260) at /Users/slate/Documents/equalizer/XCode/../lib/client/aglWindow.cpp:393
#13 0x2a01eb32 in eq::AGLWindow::configInit (this=0x400d260) at /Users/slate/Documents/equalizer/XCode/../lib/client/aglWindow.cpp:148
#14 0x2a0a25b9 in eq::Window::configInitOSWindow (this=0x283795f0, initID=0) at /Users/slate/Documents/equalizer/XCode/../lib/client/window.cpp:435
#15 0x2a09f31b in eq::Window::configInit (this=0x283795f0, initID=0) at /Users/slate/Documents/equalizer/XCode/../lib/client/window.cpp:394
#16 0x2a0a1226 in eq::Window::_cmdConfigInit (this=0x283795f0, command=@0x4009120) at /Users/slate/Documents/equalizer/XCode/../lib/client/window.cpp:720
#17 0x2a0ae8d5 in eq::net::CommandFunc<eq::net::Dispatcher>::operator() (this=0x1ed023b4, command=@0x4009120) at commandFunc.h:50
#18 0x2a0adf4a in eq::net::Dispatcher::invokeCommand (this=0x283795f0, command=@0x4009120) at /Users/slate/Documents/equalizer/XCode/../lib/net/dispatcher.cpp:121
#19 0x2a102ec4 in eq::net::Session::_invokeObjectCommand (this=0x3061600, command=@0x4009120) at /Users/slate/Documents/equalizer/XCode/../lib/net/session.cpp:622
#20 0x2a10448c in eq::net::Session::invokeCommand (this=0x3061600, command=@0x4009120) at /Users/slate/Documents/equalizer/XCode/../lib/net/session.cpp:575
#21 0x2a0901d3 in eq::Pipe::_runThread (this=0x28377c00) at /Users/slate/Documents/equalizer/XCode/../lib/client/pipe.cpp:310
#22 0x2a0987e4 in eq::Pipe::PipeThread::run (this=0x28377a80) at pipe.h:419
#23 0x2a01a307 in eq::base::Thread::_runChild (this=0x28377a80) at /Users/slate/Documents/equalizer/XCode/../lib/base/thread.cpp:125
#24 0x2a01a48d in eq::base::Thread::runChild (arg=0x28377a80) at /Users/slate/Documents/equalizer/XCode/../lib/base/thread.cpp:101
#25 0x958aea19 in _pthread_start ()
#26 0x958ae89e in thread_start ()

感谢关于设置env NSAutoreleaseHaltNoPool = YES的提示。为什么_cocoaAppApplicationEventHandler甚至涉及到这里?我正在将一个AGL / Carbon插件导入CGL / Cocoa应用程序...... Cocoa是否已经获得了全部碳?

根据MacWindows.h

/*
 *  [Mac]ShowWindow()
 *  
 *  Mac OS X threading:
 *    Not thread safe
 *  
 *  Availability:
 *    Mac OS X:         in version 10.0 and later in Carbon.framework [32-bit only]
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Non-Carbon CFM:   in InterfaceLib 7.1 and later
 */
#if TARGET_OS_MAC
    #define MacShowWindow ShowWindow
#endif
extern void 
MacShowWindow(WindowRef window)                               AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER;

它应该只是一个直接的碳呼叫...所以我不知道为什么Cocoa正试图管理它。它似乎很奇怪,它在这里不起作用 - 但它在另一个项目中工作正常。项目之间的所有配置设置等都是相同的,所以我很难理解为什么这是一个问题。

-S!

1 个答案:

答案 0 :(得分:1)

哎,

因此,如果其他人正在寻找类似的答案,我会发布我发现的内容。

答案是Carbon Window是作为Cocoa应用程序的Cocoa插件的一部分生成的。因此,Carbon Window需要遵循Carbon Cocoa中的所有内存管理规则。因此,为什么会创建对NSCarbonWindow的引用并尝试将其添加到自动释放池中。

1)解决方案是不使用Carbon(duh),因为Apple比Adobe更快地弃用它。 :P

2)另一种解决方案是手动添加碳窗口并正确管理内存。由于我使用的是Carbon API,我无法真正做到这一点。

3)第三种解决方案是将程序分开。在单独的.app中使用Carbon API而不是Cocoa插件。这是我必须要做的,只需通过MachPorts或两个应用之间的东西传递信息。

希望这有助于其他人。 Mt个人建议当然是#1。

-Stephen