Problem drawing pictures after calling RunApplicationEventLoop

petr6534
Unregistered
 
Post: #1
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.
Quote this message in a reply
dair
Unregistered
 
Post: #2
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.
Quote this message in a reply
petr6534
Unregistered
 
Post: #3
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?
Quote this message in a reply
petr6534
Unregistered
 
Post: #4
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.
Quote this message in a reply
dair
Unregistered
 
Post: #5
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?
Quote this message in a reply
petr6534
Unregistered
 
Post: #6
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cocoa/OpenGL drawing full-screen problem ultitech 5 8,424 Jan 13, 2011 01:11 PM
Last Post: SethWillits
  Better way of calling a function in another class? brush 5 4,376 Jun 12, 2008 11:23 PM
Last Post: AnotherJake
  Writing an ObcJ function/calling it from C++ Jones 20 9,086 Nov 21, 2006 06:32 PM
Last Post: OneSadCookie