just... weird
Depending on when and where I call the following method, my OpenGL lighting will either work intermittently or not at all. Can anyone suggest a mechanism for this:
to be changing how my lighting works? My sanity is slowly but surely leaking away.
Code:
- (void) resetCursorPosition
{
if (CGDisplayIsCaptured(kCGDirectMainDisplay))
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, CGPointMake(width/2, height/2));
}to be changing how my lighting works? My sanity is slowly but surely leaking away.
You're using Cocoa, right? Isn't there some Cocoa method you can use that changes the cursor position?
I just had a whacky bug last week that caused all kinds of stuff to go weird with both texturing AND lighting. Still don't know what caused it, but I turned off texturing just before returning from the drawing timer and it works fine now. And no, I didn't forget to leave it on somewhere else. And no, it wasn't expected to be on when the timer was supposed to start again. The bug would only hit when I wanted to conditionally call a simple routine to display fps in either textured fonts or bitmapped ( I tried both ). But I went back over everything and well, it was just weird...
Have you checked to see you're not trashing any memory (try MallocDebug)?
Just guessing, but try making sure your GL context is current before submitting commands. If you use threads, multiple contexts, or do anything outside of the normal NSOpenGLView drawRect, it's possible your GL commands are going into dev/null.
On Mac OS X, issuing OpenGL commands without a current context usually causes a crash rather than a silent error (as it often does on other platforms).
MallocDebug claims no trashed memory. Might it be wrong? I'm no expert when it comes to interpreting these things.
I call CGLSetCurrentContext() just before I set up my lights, so I don't think that's it.
I call CGLSetCurrentContext() just before I set up my lights, so I don't think that's it.
:envy:
OSC, you are - as ever - entirely right. The reason I didn't know I was "trashing memory" was because I didn't realise the memory needed to stay untrashed, and I was just entering a method, declaring an array, calling glLightfv, and going merrily on my way.
The numbers now live permanently in allocated storage, and everything looks peachy (well... at least it looks how I expect it to look).
Thanks again.
OSC, you are - as ever - entirely right. The reason I didn't know I was "trashing memory" was because I didn't realise the memory needed to stay untrashed, and I was just entering a method, declaring an array, calling glLightfv, and going merrily on my way.
The numbers now live permanently in allocated storage, and everything looks peachy (well... at least it looks how I expect it to look).
Thanks again.
That seems odd... you shouldn't have to put light positions/colors/whatever into the heap, OpenGL should copy them when you make the call... makes me think you've got something even more dodgy going on!
Damn and blast. It seemed weird and counterintuitive, but it worked so nicely I thought that had to be it, despite no example I've ever seen bothering to do that.
Why did you suggest trashed memory originally?
This happened once before, but it started working again for no apparent reason, which made me nervous even then. Um... any suggestions?
Why did you suggest trashed memory originally?
This happened once before, but it started working again for no apparent reason, which made me nervous even then. Um... any suggestions?
I suggested trashed memory because usually when two completely unrelated pieces of code interact, it's caused by memory trashing...
If MallocDebug's not helping, set up the code so that you see the problem, then do a "binary search" for the problem by commenting out large amounts of code until it works, uncommenting some of that code until it doesn't, &c.
If MallocDebug's not helping, set up the code so that you see the problem, then do a "binary search" for the problem by commenting out large amounts of code until it works, uncommenting some of that code until it doesn't, &c.
Eww.
The trouble is, I was doing pretty much that for a couple of days before I posted, and all I managed to do was change the precise symptoms displayed. Now it's working, I think I'm going to leave it for a while - if it comes back to bite me later, I don't think it'll be any worse than it was before...
...stay tuned for Return of the Amazing Incomprehensible Showstopper Lightingbug: Jaws of Vengeance
.
The trouble is, I was doing pretty much that for a couple of days before I posted, and all I managed to do was change the precise symptoms displayed. Now it's working, I think I'm going to leave it for a while - if it comes back to bite me later, I don't think it'll be any worse than it was before...
...stay tuned for Return of the Amazing Incomprehensible Showstopper Lightingbug: Jaws of Vengeance
.

