GrabInput and ShowCursor(false)

Hi. I am implementing a mouselook that toggles on when the mouse button is
pressed. When the user presses the left mouse button I call
SDL_ShowCursor(0) and SDL_WM_GrabInput(SDL_GRAB_ON) in that order. 95% of
the time this creates a mouse wraping effect such that the user can move the
mouse infinitely in any direction, but sometimes it stops the mouse from
generating relative motion events once the cursor reaches the window’s
edges. This can also happen in fullscreen mode.

I have seen the hack where you use SDL_WarpMouse to move the mouse to the
center when it reaches the window edges, but I am wondering if there is a
correct way to fix my problem? Usually if I click outside the window, then
click the window again it will start behaving. This problem occurs in
Linux, OSX, and Windows builds.