Problem drawing pictures after calling RunApplicationEventLoop
I have a game where I've installed a couple of carbon event handlers. Basically, after the user presses a button, I want an image to appear on the screen. I've written a function to do the drawing. After I call RunApplicationEventLoop(), I have the user press a button. Now my callback function is envoked, and I make a call to my function to draw the image. The program crashes at this point, and when I debug the program, I find that when I call my Draw function, my CGrafPtr instance contains nothing. I know there's nothing wrong with my drawing code because when I call my function to draw the image before calling RunApplicationEventLoop, the image is drawn successfully. I'm not exactly sure what's going on. Any help would be great.
If you're drawing to a CGrafPtr, are you setting the port from within your draw function?
Unless the event that triggered your callback is documented to set the port (e.g., kEventWindowDrawContent), you'll need to re-establish the port before you draw.
Unless the event that triggered your callback is documented to set the port (e.g., kEventWindowDrawContent), you'll need to re-establish the port before you draw.
I am setting the port from within my draw function, but it doesn't work. When I debug and after I run that line of code, the CGrafPtr contains nothing. Is there something else that I'm missing?
More specifically, when I execute the function CGrafPtr thePort = GetWindowPort(window) inside my draw function, thePort contains nothing. If I make a call to my draw function before calling RunApplicationEventLoop, everything works fine. But when I make a call to my draw function after the user presses the space bar, for example, thePort contains nothing and the app crashes. Still not sure what's causing this.
A WindowRef always has a port associated with it, so if GetWindowPort() is giving you NULL I suspect your window has been disposed of. Try calling IsValidWindowPtr() on your window, and I imagine you'll get back false at this point as well - do you ever call DisposeWindow on your window?
I don't call DisposeWindow at all, but I do suspect where the problem is coming from; although I don't know how to fix it. Since I've declared my carbon event callback function inside one of my classes, I had to declare it static. From inside this function, I've used my typecasted object pointer to call my drawing function. I'm guessing there's a problem when it's trying to access the window by calling it through my static callback function. I added the line CGrafPtr thePort = GetWindowPort(window) inside my static callback function, and this time I get a compiler error that says "Invalid use of member 'MyClass::window' in static member function." I'm not exactly sure, however, how to resolve this problem.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Cocoa/OpenGL drawing full-screen problem | ultitech | 5 | 7,035 |
Jan 13, 2011 01:11 PM Last Post: SethWillits |
|
| Better way of calling a function in another class? | brush | 5 | 3,908 |
Jun 12, 2008 11:23 PM Last Post: AnotherJake |
|
| Writing an ObcJ function/calling it from C++ | Jones | 20 | 8,115 |
Nov 21, 2006 06:32 PM Last Post: OneSadCookie |
|

