Left mouse button causes moueup event despite button still being pressed.

Apprentice
Posts: 9
Joined: 2008.06
Post: #16
Thanks all for the responses!

I've replaced glutWarpPointer with CGWarpMouseCursorPosition(pos) and that works just fine. (With a couple of weirdo bugs that I'm just trying to iron out now)

Thanks for the tip about the integer limits, i hadn't considered that.
Quote:Can you describe what you're attempting to actually do? The code you've shown is very odd looking; it may very well be that there is a different and more robust approach -- one which will fit better within the functionality GLUT offers.

I'm attempting to get input from the mouse buttons and at the same time do a mouse look thing. I'm using incremented integers because I figure, why use an INT and a BOOL, when you can do the same thing with just an INT?

Quote:have you stuck a printf at the top level of the HandleMousePress function to see what GLUT is giving you?

I don't actually know how to use printf. I suppose that's something I should learn. And the INTs are signed.

Quote:I don't know if this is at all relevant, but every time you call glutWarpPointer(), mouseMovement (or whatever the name is) function is called

Yep I considered that and tried commenting out some lines and changing functions around but it had no effect.

...

Well that solves my problem Smile Thanks everyone for all your help (especially AnotherJake), I really really appreciate it!
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #17
QuestingCordiial Wrote:I don't actually know how to use printf. I suppose that's something I should learn.

printf("hello I am at this line\n");
or
printf("HandleMousePress called with button:%d buttonstate:%d\n", button, state);

You can have as many escape sequences as you like. %d will print an integer, %f a float and there are a bunch of other ones. Then you stick a comma separated list of the variables at the end to match the escape sequences.

And if you use Cocoa, NSLog is more flexible than printf, though it appears to be pure C you are writing.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #18
You MUST heed reubert's advice here! printf (and NSLog if you're doing Cocoa) are absolutely indispensable for nailing bugs down!

BTW, I've gotten into the habit of also including a fflush(stdout) after every printf when debugging, just to make certain it gets sent. Don't know any technical details behind whether or not that's worth the trouble though...
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #19
I think that is to do with newlines at the end, ie. it doesn't get flushed until a newline character. I could be wrong though. My examples above have been edited with the \n at the end, as this is how they should have been.

NSLog does not require the newline at the end.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2008.06
Post: #20
But where does the printed text get displayed?
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #21
stdout, which is the console by default -- which would be the system console if the app is running on its own, or the Xcode debugger console if launched from within Xcode.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2008.01
Post: #22
reubert Wrote:I think that is to do with newlines at the end, ie. it doesn't get flushed until a newline character. I could be wrong though. My examples above have been edited with the \n at the end, as this is how they should have been.

NSLog does not require the newline at the end.

stdout is line buffered by default.

I suggest you read
man setvbuf

for more information (also how to change printf behaviour).

stderr is not buffered by default.
Quote this message in a reply
Member
Posts: 254
Joined: 2005.10
Post: #23
If you are using xcode, you should set it to always display the console when you do a build and run. That way you can see the results as the program is running. You can find this setting in Preferences > Debugging, select "On Start: Show Console".
Quote this message in a reply
Moderator
Posts: 453
Joined: 2008.04
Post: #24
Blacktiger Wrote:If you are using xcode, you should set it to always display the console when you do a build and run. That way you can see the results as the program is running. You can find this setting in Preferences > Debugging, select "On Start: Show Console".

Ooh, thank you! I didn't know about that one :O
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2008.06
Post: #25
Yes that's going to be very handy!
Quote this message in a reply
Member
Posts: 254
Joined: 2005.10
Post: #26
AndyKorth Wrote:Ooh, thank you! I didn't know about that one :O

Heh, I didn't either, but I've been reading "Cocoa Programming for Mac OS X" (3rd ed) lately and that was one of the things the book mentioned.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #27
I simply cannot imagine programming without immediate visual access to console output from printf's (and logs from Cocoa) -- I thought everyone needed that. It's been integral to my style of programming for nearly twenty years. To me, during development, not having the console visible during execution would be analogous to the proverbial "having one hand tied behind my back"!
Quote this message in a reply
Moderator
Posts: 624
Joined: 2007.09
Post: #28
I have a 15-inch monitor and as such must conserve space, which means I sometimes am forced not to be able to see everything I'd like to at once. I didn't know about it either though.

- Lincoln Green
http://www.binkworks.com/
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #29
Hairball183 Wrote:I have a 15-inch monitor and as such must conserve space, which means I sometimes am forced not to be able to see everything I'd like to at once. ...

Well obviously you don't always get to see it, depending on the situation (e.g. full screen on a single display setup, or a maximized window), but I prefer to have at least the bottom line of the console peaking out somewhere if at all possible, unless I know for a fact that I won't be seeing any output or don't happen to care about output at the time. Screen space doesn't really have anything to do with it -- I used to do this on the 9-inch 512 x 342 pixel display in my Mac Classic back in the day too.

At one point, I seem to recall that the developer tools I was using did not conveniently display console output so I bought a third-party utility to help. I think that utility was called D-Con; which I thought was a pretty clever name for "Debug-Console" and at the same time alluding to a popular rodent poison. It was pretty neat because it had a small console window always floating at the tool palette level, so it showed up even over the program being debugged.

printf'ing is a very powerful method for debugging! For instance, if you have a bug in your program somewhere, but you just can't see it out of thousands of your lines of code, simply start sectioning off large parts with printf's. Then you'll narrow things down by "bracketing" that subsection with more printf's, and repeating the process until you get down to a more narrow area and start setting debugger breakpoints, or continue subdividing the sections of code to get even further down to a few lines or even just one. The general idea goes something like this:

Code:
void MyMegaFunction(void)
{
    code
    ...
    printf("here 1\n");
    ...moreCode...
    printf("here 2\n");
    ...moreCode...
    BUG WHICH CAUSES CRASH
    ...moreCode...
    printf("here 3\n");
    ...
}

Which would produce this console output:
Code:
here 1
here 2
Which would indicate to you immediately that the section where the bug is at is between here 2 and here 3, so you can start sprinkling printf's in that area next.

I've heard of this being called the "divide and conquer" method of bug hunting with printf, but this is just bug hunting 101 to me. Wink
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  customize an action of iphone home button to submit score in gamecenter sefiroths 7 7,674 Nov 30, 2011 01:59 AM
Last Post: sefiroths
  only one error left! Please help... Kingbry 10 4,999 Sep 11, 2007 01:38 AM
Last Post: OneSadCookie
  Mouse button enabler, like GamePad Companion setera 4 4,516 Apr 30, 2006 06:32 PM
Last Post: setera
  Event Handling (Keyboard and Mouse) bwalters 6 7,577 Mar 12, 2006 08:17 PM
Last Post: OneSadCookie
  Configurable keys - describe key that was pressed MattDiamond 13 7,299 Oct 27, 2003 11:23 PM
Last Post: OneSadCookie