Strange OpenGl or NSBitmapImageRep error

Nibbie
Posts: 3
Joined: 2009.04
Post: #1
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.
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #2
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.

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #3
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.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2009.04
Post: #4
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!
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2009.04
Post: #5
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  iPhone 3GS OpenGL strange framerate bug airfire 2 3,404 Dec 2, 2009 09:22 AM
Last Post: airfire
  NSBitmapImageRep/CIImage questions Caveman 6 5,970 Sep 6, 2008 04:37 PM
Last Post: ThemsAllTook
  Copying between NSBitmapImageRep objects Emehr 3 4,044 Oct 31, 2007 01:27 PM
Last Post: Emehr
  Error trying to link an OpenGL app memon 4 3,608 Mar 19, 2007 12:33 PM
Last Post: memon
  NSBitmapImageRep ICC profile stripping? kelvin 0 2,058 Mar 9, 2006 05:42 PM
Last Post: kelvin