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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:31:58+00:00 2026-06-06T19:31:58+00:00

I am writing a Cocoa OpenGL app and running my main loop with a

  • 0

I am writing a Cocoa OpenGL app and running my main loop with a CVDisplayLink per this technical note. It works fine for running the loop.

The problem is that sometimes when I quit, my display link callback will be called on its own thread after my application has already quit. This causes my rendering code to get called and crash as soon as I call any OpenGL function (glClear in this case), because my context no longer exists.

I have CVDisplayLinkRelease(displayLink); in my NSView’s dealloc function, but it never seems to get called, I’m assuming because of ARC. Is there someway I can ensure that my display link is destroyed before my view?

Edit: I didn’t notice the crash is actually being triggered by an assert I have. I assert on glGetError after each OpenGL call I make to make sure I can catch bugs early. After a call to glClear or [[view openGLContext] flushBuffer]; I get error 1286, which is GL_INVALID_FRAMEBUFFER_OPERATION.

That makes logical sense because my window and thus view are being deallocated, but it doesn’t help the problem. I don’t want to just ignore those errors because they could obviously happen in more cases than just this. I still need to find the “right” way to ensure my display link is shut down before my view.

  • 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-06T19:32:00+00:00Added an answer on June 6, 2026 at 7:32 pm

    When an application terminates, nothing in its autorelease pool gets released—the application simply exits and lets the operating system clean up the memory. Since nothing gets released, nothing receives a dealloc message.

    This means two things:

    • You should not tie the lifetime of files, connections, or anything else that does not solely reside in memory to the lifetime of an object.
    • You should ensure that you end those things’ lifetimes in response to termination as well as deallocation.

    There are two ways to handle termination. The way I usually do it in a single-window app is by having my application’s delegate be nothing else, and directly own my primary window controller. The other way is to add yourself as an observer for the NSApplicationWillTerminate notification and respond to it by, e.g., stopping your display link.

    If any part of your cleanup may take some time, your application’s delegate should respond to applicationShouldTerminate: by returning NSTerminateLater, and you should send the application a replyToApplicationShouldTerminate: message when you’re done with whatever you needed to do.

    The other solution to the original problem—your CVDisplayLink callback getting called before you have a chance to close the link—is the complete opposite: Enable sudden termination. When that is enabled, your application will quit by sending itself SIGKILL (better known by the command-line invocation kill -9), which means that every one of your threads will stop immediately.

    Of course, if you have anything that really does need to be cleaned up (lock files, network connections, etc.), then you should disable sudden termination around those things’ lifetime, and be prepared for regular termination during that time.

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

Sidebar

Related Questions

I'm writing a Cocoa app in Objective C that's communicating with a webservice and
I'm writing a Cocoa application where I have an auto generated app delegate:(MyAppDelegate.h/MyAppDelegate.m) So
Let's say, for illustration, I was writing an iTunes clone app in Cocoa, that
I'm writing a Cocoa app that will need access to multiple file transfer protocols,
The Problem I'm writing a Cocoa application and I want to raise exceptions that
I'm writing code in AppleScript to glue an Obj-C Cocoa app to some other
I'm writing a Cocoa app using the document architecture. Whenever an untitled document is
I am writing a Cocoa App to display a 2-d floating array. I now
I'm writing a Cocoa app and basically I have a window and I need
I'm writing a Cocoa app for Leopard that, given a directory of text files,

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.