Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

CGBitmapContextCreateImage: invalid context

When drawing labels in a window (pretty basic), I get the following errors:

Fri Oct 22 21:18:24 MacBook.local TestApp[460] <Error>: CGContextConcatCTM: invalid context 0x0
Fri Oct 22 21:18:24 MacBook.local TestApp[460] <Error>: CGContextSetInterpolationQuality: invalid context 0x0
Fri Oct 22 21:18:24 MacBook.local TestApp[460] <Error>: CGContextDrawImage: invalid context 0x0
Fri Oct 22 21:18:24 MacBook.local TestApp[460] <Error>: CGBitmapContextCreateImage: invalid context 0x0

Most of the time these errors can be ignored, but some time they seem to result in the application crashing or the labels not being drawn.

I was curious how I can go about troubleshooting this. The offending code seems to be this (the 2nd label causes the messages):


            var gaugeBackground = Titanium.UI.createImageView({
                image:'gauge-na.png',
                top:90,
                left:10,
                height:12,
                align:'left',
                width:100
            });
            Titanium.UI.currentWindow.add(gaugeBackground);

            var labelGauge = Titanium.UI.createLabel({
                align:'left',
                width:itemValue,
                height:12,
                left:10,
                top:90,
                borderWidth:1,
                borderColor:'gray',
                backgroundImage:'gauge-value.png'
            });

            Titanium.UI.currentWindow.add(labelGauge);

This draws a label on top of a previously created label (to simulate a partially filled horizontal gauge).

As I mentioned earlier, sometimes running this code results in the application freezing, though it works most of the time. There definitely seems to be something odd going on.

Thanks for any suggestions.

— asked October 23rd 2010 by Ingmar Koecher
  • iphone
  • label
  • mobile
0 Comments

4 Answers

  • yup move the backgroundImage to a view and add your label to that view

    — answered November 19th 2010 by ben nduati
    permalink
    3 Comments
    • I changed from label to view and the error is gone.

      var labelGauge = Titanium.UI.createLabel >> is now >> var labelGauge = Titanium.UI.createView

      — commented January 18th 2011 by Joao Silva
    • I changed from label to view and the error is gone too!

      — commented May 26th 2011 by david brewer
    • this seemed to work for me too.

      — commented July 16th 2011 by Sam Shupac
  • Hi there Ingmar,

    I get these constantly - it's pretty annoying. but I've found that:

    1. They don't seem to indicate a functional issue in the app (although it can't be a good sign!)
    2. They are directly related to setting a backgroundImage to a label

    Do you get the freezing if you remove the borderwidth and bordercolor from the second label?

    cheers,
    Chris.

    — answered November 9th 2010 by Chris Reed
    permalink
    0 Comments
  • Hi there Ingmar,

    I get these constantly - it's pretty annoying. but I've found that:

    1. They don't seem to indicate a functional issue in the app (although it can't be a good sign!)
    2. They are directly related to setting a backgroundImage to a label

    Do you get the freezing if you remove the borderwidth and bordercolor from the second label?

    cheers,
    Chris.

    — answered November 9th 2010 by Chris Reed
    permalink
    0 Comments
  • Thank you Chris.

    You might be right, these messages are only fired when I set a background. I have another discussion open (http://developer.appcelerator.com/question/76231/bug-creating-two-imageviews-on-top-of-each-other-causes-freeze-every-time), and it seems the problem is not related to the background image.

    Using the 1.5 SDK, the app now crashes instead of freezing.

    I can remove all properties, and just create an empty label without any properties, and it will still freeze (v1.4) or crash (v1.5).

    I'm just not sure what to do. My app is essentially finished, but I'm in limbo.

    I also have a sample app that will illustrate this if you are interested?

    — answered November 9th 2010 by Ingmar Koecher
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.