Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

QCRenderer Leak



I have a window with a custom NSView, and I want to use QCRenderer to draw a qtz file. I know this can be done using QCView much easier, but I need to run a Cocoa method on mouseDown and I can't see how to do that with QCView. So when I run the following code I get the basic qtz being drawn, but there is a memory leak I cannot locate, and the compositions time is incorrect. Basically the clock in the qtz keeps getting reset every few seconds. Any help is appreciated, thank you.



#import <OpenGL/CGLMacro.h>
#import <Cocoa/Cocoa.h>

#import "AppController.h"

#define kRenderFPS 60.0

@implementation AppController

- (void) applicationDidFinishLaunching:(NSNotification*)notification
{
    NSOpenGLPixelFormatAttribute    attributes[] = {NSOpenGLPFAAccelerated, NSOpenGLPFANoRecovery, NSOpenGLPFADoubleBuffer,  NSOpenGLPFADepthSize, 24, 0};
    long                            swapInterval = 1;

    

    //Create the OpenGL context used to render the animation and attach it to the rendering view
    _glPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
    _glContext = [[NSOpenGLContext alloc] initWithFormat:_glPixelFormat shareContext:nil];
    [_glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
    [_glContext setView:renderView];

    

    //We need to know when the rendering view frame changes so that we can update the OpenGL context
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateRenderView:) name:NSViewFrameDidChangeNotification object:renderView];

    

    //Create a timer which will regularly call our rendering method
    _renderTimer = [[NSTimer timerWithTimeInterval:(1.0 / (NSTimeInterval)kRenderFPS) target:self selector:@selector(_renderGLScene:) userInfo:nil repeats:YES] retain];
    [[NSRunLoop currentRunLoop] addTimer:_renderTimer forMode:NSDefaultRunLoopMode];
    [[NSRunLoop currentRunLoop] addTimer:_renderTimer forMode:NSModalPanelRunLoopMode];
    [[NSRunLoop currentRunLoop] addTimer:_renderTimer forMode:NSEventTrackingRunLoopMode];
    _startTime = -1.0;
}

- (void) _renderGLScene:(NSTimer*)timer
{
    CGLContextObj            cgl_ctx = [_glContext CGLContextObj]; //By using CGLMacro.h there's no need to set the current OpenGL context
    NSTimeInterval            time = [NSDate timeIntervalSinceReferenceDate];

    

    //Compute the local time
    if(_startTime < 0.0)
    _startTime = time;
    time = time - _startTime;

    

    //Clear background
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    

    //Create the filepath to the specified file
    NSString* _filePath = [[NSBundle mainBundle] pathForResource:@"Chemical Burn" ofType:@"qtz"];

    //Create the QuartzComposer Renderer with that OpenGL context and the specified composition file
    _renderer = [[QCRenderer alloc] initWithOpenGLContext:_glContext pixelFormat:_glPixelFormat file:_filePath];
    if(_renderer == nil) {
        NSLog(@"Cannot create QCRenderer");
        [self release];
    }

    //Render a frame
    if(![_renderer renderAtTime:time arguments:nil])
        NSLog(@"Rendering failed at time %.3fs", time);

    

    //Display new frame
    [_glContext flushBuffer];

}

- (void) updateRenderView:(NSNotification*)notification
{
    CGLContextObj            cgl_ctx = [_glContext CGLContextObj]; //By using CGLMacro.h there's no need to set the current OpenGL context
    NSRect                    frame = [renderView frame];

    

    //Notify the OpenGL context its rendering view has changed
    [_glContext update];

    

    //Update the OpenGL viewport
    glViewport(0, 0, frame.size.width, frame.size.height);

    

    //Render OpenGL scene immediately
    [self _renderGLScene:nil];
}

- (void)mouseDown:(NSEvent *)event
{
    NSLog(@"Click");
}

- (void) dealloc
{
    [_renderTimer release];
    [_renderer release];
    [_glContext release];
    [_glPixelFormat release];    

    

    [super dealloc];
}

@end
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.