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 7029743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:34:43+00:00 2026-05-28T00:34:43+00:00

ok so im trying to make it so that when my app opens, the

  • 0

ok so im trying to make it so that when my app opens, the cursor changes, but to change it im putting an image overlay. So here is the code i have…

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
        // get the cursor image 
        NSPoint mouseLoc; 
        mouseLoc = [NSEvent mouseLocation]; //get cur

        NSLog(@"Mouse location is x=%d,y=%d",(int)mouseLoc.x,(int)mouseLoc.y);

        // get the mouse image 
        NSImage *overlay    =   [[[NSCursor arrowCursor] image] copy];

        NSLog(@"Mouse location is x=%d,y=%d cursor width = %d, cursor height = %d",(int)mouseLoc.x,(int)mouseLoc.y,(int)[overlay size].width,(int)[overlay size].height);

        int x = (int)mouseLoc.x;
        int y = (int)mouseLoc.y;
        int w = (int)[overlay size].width;
        int h = (int)[overlay size].height;
        int org_x = x;
        int org_y = y;

        size_t height = CGImageGetHeight([NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]]);
        size_t width =  CGImageGetWidth([NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]]);
        int bytesPerRow = CGImageGetBytesPerRow([NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]]);

        unsigned int * imgData = (unsigned int*)malloc(height*bytesPerRow);

        // have the graphics context now, 
        CGRect bgBoundingBox = CGRectMake (0, 0, width,height);

        CGContextRef context =  CGBitmapContextCreate(imgData, width, 
                                                      height, 
                                                      8, // 8 bits per component 
                                                      bytesPerRow, 
                                                      CGImageGetColorSpace([NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]]), 
                                                      CGImageGetBitmapInfo([NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]]));

        // first draw the image 
        CGContextDrawImage(context,bgBoundingBox,[NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]]);

        // then mouse cursor 
        CGContextDrawImage(context,CGRectMake(0, 0, width,height),[NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]]);

        // then mouse cursor 
        CGContextDrawImage(context,CGRectMake(org_x, org_y, w,h),[overlay CGImageForProposedRect: NULL context: NULL hints: NULL] );


        // assuming both the image has been drawn then create an Image Ref for that 

        CGImageRef pFinalImage = CGBitmapContextCreateImage(context);

        CGContextRelease(context);

        return pFinalImage; /* to be released by the caller */
    }

So ive tried this and it compiles with warnings regarding the url path but it has no errors. But when i open the app, it crashes! So can anyone help me out?

  • 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-05-28T00:34:43+00:00Added an answer on May 28, 2026 at 12:34 am

    You’re taking an NSURL* and passing it to functions that take a CGImageRef. That isn’t even close to making sense, so I don’t know why you didn’t get errors. To load a CGImage from a URL, you need to use the CGImageSource functions like CGImageSourceCreateWithURL.

    P.S., rather than just saying it crashes, run it under the debugger and find out exactly where it crashes.

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

Sidebar

Related Questions

I am trying to make an app that opens android market page of selected
I am trying to make an app that will pass data between two servers
I'm trying to make a console app that would monitor some process and restart
I'm trying to make a simple app that sits on the Mac OSX menu
I am trying to make a web app in Dashcode that uses a range
I'm trying to make test-program that opens a website by pushing a button. I
I am trying to make a simple app that read from a midi port
I am trying to make my app rotation friendly, but I am having some
I'm at the moment trying to make a very simple app that will greet
On my application I am trying to make it so that it opens a

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.