just... weird

w_reade
Unregistered
 
Post: #1
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:

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.
Quote this message in a reply
DJBlufire
Unregistered
 
Post: #2
You're using Cocoa, right? Isn't there some Cocoa method you can use that changes the cursor position?
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #3
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...
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Have you checked to see you're not trashing any memory (try MallocDebug)?
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #5
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
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).
Quote this message in a reply
w_reade
Unregistered
 
Post: #7
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.
Quote this message in a reply
w_reade
Unregistered
 
Post: #8
: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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
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!
Quote this message in a reply
w_reade
Unregistered
 
Post: #10
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
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.
Quote this message in a reply
w_reade
Unregistered
 
Post: #12
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 Wink.
Quote this message in a reply
kberg
Unregistered
 
Post: #13
Sounds like bad pointers or array overflowing to me... :sorry:
Quote this message in a reply
Post Reply