Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8645071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:27:19+00:00 2026-06-12T12:27:19+00:00

EDIT: I tried using the push/pop thing, but now it crashes. I have a

  • 0

EDIT: I tried using the push/pop thing, but now it crashes.

I have a feeling what I’m attempting to do is way off.. Is there any way to just get core graphics showing up on the screen? I need something thats able to be updated every frame, like drawing a line between two points that always move around..
Even if someone knows of a complete alternative Ill try it.

in .h

CGContextRef context;

in .m

in init method

int width = 100;
int height = 100;

void *buffer = calloc(1, width * height * 4);
context = CreateBitmapContextWithData(width, height, buffer);

CGContextSetRGBFillColor(context, 1, 1, 1, 1);
CGContextAddRect(context, CGRectMake(0, 0, width, height));
CGContextFillPath(context);

CGImageRef image = CGBitmapContextCreateImage(context);

hud_sprite = [CCSprite spriteWithCGImage:image key:@"hud_image1"];

free(buffer);
free(image);

hud_sprite.anchorPoint = CGPointMake(0, 0);
hud_sprite.position = CGPointMake(0, 0);

[self addChild:hud_sprite z:100];

in a method I call when I want to update it.

int width = 100;
int height = 100;

UIGraphicsPushContext(context);

    CGContextClearRect(context, CGRectMake(0, 0, width, height)); //<-- crashes here. bad access...

    CGContextSetRGBFillColor(context, random_float(0, 1),random_float(0, 1),random_float(0, 1), .8);
    CGContextAddRect(context, CGRectMake(0, 0, width, height));
    CGContextFillPath(context);

    CGImageRef image = CGBitmapContextCreateImage(context);

UIGraphicsPopContext();

//CGContextRelease(ctx);

[[CCTextureCache sharedTextureCache] removeTextureForKey:@"hud_image1"];
[hud_sprite setTexture:[[CCTextureCache sharedTextureCache] addCGImage:image forKey:@"hud_image1"]];

free(image);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:27:20+00:00Added an answer on June 12, 2026 at 12:27 pm

    You are calling UIGraphicsPushContext(context). You must balance this with UIGraphicsPopContext(). Since you’re not calling UIGraphicsPopContext(), you are leaving context on UIKit’s graphics context stack, so it never gets deallocated.

    Also, you are calling UIGraphicsBeginImageContext, which creates a new graphics context that you later release (correctly) by calling UIGraphicsEndImageContext. But you never use this context. You would access the context by calling UIGraphicsGetCurrentContext, but you never call that.

    UPDATE

    Never call free on a Core Foundation object!

    You are getting a CGImage (which is a Core Foundation object) with this statement:

    CGImageRef image = CGBitmapContextCreateImage(context);
    

    Then later you are calling free on it:

    free(image);
    

    You must never do that.

    Go read the Memory Management Programming Guide for Core Foundation. When you are done with a Core Foundation object, and you have ownership of it (because you got it from a Create function or a Copy function), you must release it with a Release function. In this case you can use either CFRelease or CGImageRelease:

    CGImageRelease(image);
    

    Furthermore, you are allocating buffer using calloc, then passing it to CreateBitmapContextWithData (which I guess is your wrapper for CGBitmapContextCreateWithData), and then freeing buffer. But context keeps a pointer to the buffer. So after you free(buffer), context has a dangling pointer. That’s why you’re crashing. You cannot free buffer until after you have released context.

    The best way to handle this is to let CGBitmapContextCreateWithData take care of allocating the buffer itself by passing NULL as the first (data) argument. There is no reason to allocate the buffer yourself in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried creating remote branch devel using: git push origin origin:refs/heads/devel But it fails
I have been using git to push my local code to a server. I
I'm developing a GUI in C++ using dev-c++. I have an edit control like
When a user is using a Detailsview or Formview in Edit mode, and tries
I tried the following: $.load(Views/chatBox.html).appendTo('body') Console Output: TypeError: $.load is not a function EDIT
Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) {
Does anyone know how can I edit a subitem on a listView? I've tried
EDIT: See my answer below--> I am wanting to have a view that when
Edit (updated question) I have a simple C program: // it is not important
EDIT: iam using ajax to load text in my content that is why onload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.