iDevGames Forums
Strange OpenGl or NSBitmapImageRep error - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Strange OpenGl or NSBitmapImageRep error (/thread-1450.html)



Strange OpenGl or NSBitmapImageRep error - magnusrw - Apr 15, 2009 04:33 PM

Howdy folks,
I've been working on an OpenGL game that has recently developed a mysterious bug. After running the program several times (like 10 or 20) two parts of the program start behaving badly. In both of these parts I am using glReadPixels to read into an NSBitmapImageRep I have created.

In one of these parts the image that is copied suddenly is turned upside down and the quality make it looks as if it were rendered without unit length normals (that's what it looks like to me, anyway).

In the other part, the copied image is just totally jumbled, though something that I draw on top of the image rep using Cocoa is just fine. The rest of the OpenGl parts of the game work fine (I don't use glReadPixels anywhere else) but they are slow as molasses once the problem manifests.

The weirdest part is that quitting and relaunching, or even quitting and relaunching Xcode does not fix this, but restarting does. I've been restarting so much I feel like I'm programming in System 7 again, but without the joy of MacsBugSmile

I loaded an old copy of my project that was backed up by Time Machine before I noticed this error and it still seems to develop the problem.
Any ideas? I'm not sure what to think.


Strange OpenGl or NSBitmapImageRep error - kodex - Apr 15, 2009 06:07 PM

For an issue like this I would run a RAM test on your hardware, sounds like something other then code might be the cause here.


Strange OpenGl or NSBitmapImageRep error - arekkusu - Apr 15, 2009 08:00 PM

If you're reading into a buffer which you use to create an NSBitmapImageRep, this should work. However, if you're trying to write into the pointer returned by bitmapData, there's no guarantee that will work. NSBitmapImage isn't a graphics context, it is an opaque image container that lets you get bits out. This means you can't read-modify-write a single NSBitmapImageRep.


Strange OpenGl or NSBitmapImageRep error - magnusrw - Apr 16, 2009 06:37 AM

arekkusu Wrote:If you're reading into a buffer which you use to create an NSBitmapImageRep, this should work. However, if you're trying to write into the pointer returned by bitmapData, there's no guarantee that will work. NSBitmapImage isn't a graphics context, it is an opaque image container that lets you get bits out. This means you can't read-modify-write a single NSBitmapImageRep.

I allocate the memory myself so that shouldn't be a problem. I was thinking that theproblem was something along the lines of what kodex suggested. I'm running on a Powerbook G4 12" 1.33Ghz. Does anyone know of anyway to test the video hardware to see if it's behaving correctly? Are there any known issues with the card in that machine? It seems to me like glReadPixels just isn't reading the pixels correctly. The whole flipped image thing is very weird though; I don't know what to make of that.

Thanks for the replies!


Strange OpenGl or NSBitmapImageRep error - magnusrw - Apr 24, 2009 11:13 AM

In case it's of interest to anyone, I did not figure out why I was having these problems, but I was able to eliminate them by using an NSTimer instead of CVDisplayLinkSetOutputCallback to call my main rendering method. I had used Core Video because somewhere I read an Apple pub saying that it was preferred for games. Chances are I was using it incorrectly.
BTW, the game is much smoother now using an NSTimer, it seems to be called at more regular intervals.

Thanks for the help.