Hello Ken!

To make it simple - here is the entire code:

        NSSize textSize = [m_string sizeWithAttributes: m_attribs];
        // Texture dimentions should be power of 2. However if the height is 
bigger than the width strange things gets drawn.
        NSSize frameSize = 
NSMakeSize(NextPowerOf2((NSInteger)(MAX(textSize.width, textSize.height))), 
NextPowerOf2((NSInteger)textSize.height));
        
        NSBitmapImageRep* textRep = [[NSBitmapImageRep alloc]
                                                                
initWithBitmapDataPlanes:NULL
                                    pixelsWide:(NSInteger)frameSize.width
                                    pixelsHigh:(NSInteger)frameSize.height
                                    bitsPerSample:8
                                    samplesPerPixel:4
                                    hasAlpha:YES
                                    isPlanar:NO
                                    colorSpaceName:NSCalibratedRGBColorSpace
                                    bytesPerRow:0
                                    bitsPerPixel:0];
        [textRep setSize: frameSize];

        [NSGraphicsContext saveGraphicsState];
        [NSGraphicsContext setCurrentContext:
                [NSGraphicsContext graphicsContextWithBitmapImageRep:textRep]];
        [[NSGraphicsContext currentContext] 
setShouldAntialias:m_fontType[eFontAntialias]];
                
        // Text is drawn from it's bottom-left, so need to compensate if the 
height was adjusted to power of 2
        [m_string drawAtPoint:NSMakePoint (0, frameSize.height - 
textSize.height) withAttributes:m_attribs];
        
        m_textureSize.width = [textRep pixelsWide]; // Size in pixels might be 
differennt from frame size 
        m_textureSize.height = [textRep pixelsHigh];// for the texture we need 
the pixel size

        NSSize bitmapSize = [textRep size];

        glPushAttrib(GL_TEXTURE_BIT);
        if (in_pImage_vec->empty())
        {
            GLuint texture = 0; 
            glGenTextures(1, &texture);
            in_pImage_vec->push_back(texture);
        }
        
        glBindTexture (GL_TEXTURE_RECTANGLE_EXT, in_pImage_vec->at(0));
        glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, 
GL_LINEAR);
        glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR);
        glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, 
GLsizei(m_textureSize.width),  GLsizei(m_textureSize.height), 0, [textRep 
hasAlpha] ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, [textRep bitmapData]);
        
        glPopAttrib();
        
        [textRep release];
        [NSGraphicsContext restoreGraphicsState];




If I omit the code AFTER NSContext creation I will still get memory leaks.
As for leak information - there are functions like:

CGContextDelegate from CGTypeCreateInstance
CGContext from CGTypeCreateInstance
CGColorTransform from CGTypeCreateInstance
NSBitmapeImageRep from -genTexture (Our function with attached code)

I have the trace file, so I can provide you additional information if you like.
Thanks again!
Dany



________________________________________
From: Ken Thomases [k...@codeweavers.com]
Sent: Monday, February 10, 2014 6:10 PM
To: Dany Golubitsky
Cc: cocoa-dev@lists.apple.com; Shai Shasag
Subject: Re: NSGraphicsContext graphicsContextWithBitmapImageRep - Memory       
leak

On Feb 10, 2014, at 2:16 AM, Dany Golubitsky wrote:

> Hello Ken and thanks for your answer!

You're welcome.

> 1) SBitmapImageRep is actually NSBitmapImageRep. N is just get lost in Copy. 
> Sorry.

Ah, I should have figured.

> 2) I tried both with release and without release of newContext. Same effect.
> 3) I am sorry for misguide a little. The drawing is not entirely with openGL. 
> The simple story is that we need to draw text. We can not do it with openGL, 
> so what we do is - we create another context with NSBitmapImageRep, we draw 
> the text there, than we draw the texture with openGL.

I'm guessing that the problem is in the code you omitted.  For example, how do 
you get the text from the bitmap context into the OpenGL drawing?

> At that point, we would like to release both textRep and newContext since we 
> do not need them anymore.
> 4) I know that this is memory leak since application memory is constantly 
> growing up to 2GB (Maybe even more). I run it with Leaks instrument. It does 
> not recognize it as leak, only as allocation.

OK, but it should show you what code is responsible for the allocation.  Also, 
if the allocation isn't an object, you may need to guess which object owns it 
and follow the retain/release history of that object, too.

> If I comment this part of code memory size reduces dramatically.

What if you only comment out the code which you omitted ("Some drawing with 
openGL")?  So, create the bitmap image rep, create the graphics context, make 
it current, then restore the previous context and release the image rep.  Don't 
do any drawing.

Regards,
Ken
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to