Skip to content

Mouse Lock Tests and Demos

December 1, 2011

Thankfully now we’re at the point where we have most of the Mouse Lock feature set from the specifications implemented, so that’s most of the work done already. Now we have to make sure that everything stays working, and that all edge cases and bugs are properly dealt with.

Last Sunday, I converted the CubicVR FPS Demo to use Mouse Lock. All of our current demos are up over here, if you have one of our current builds with mouse lock in it. It showed it off pretty well how Mouse Lock in the browser can work for a game.

Now I also have to write a few tests, mainly to see if pointer.lock() and pointer.unlock() are working as they should under different conditions, and that the success and failure callbacks from pointer.lock() are firing at the right times. So I looked at the current mouselock mochitest example, which had some of this already done (mouselock/test_fullscreen.html). The first thing I saw was that it was trying to work off a setTimeout for mozRequestFullScreen(), instead of doing it on load, so I changed that. I ended up doing most of my logic inside the “mozfullscreenchange” event, since it’s pretty easy to check for different things relating to mouse lock in there. So I’m doing different tests, and find out randomly that pointer.lock(null) will actually break the browser in the current build. So I look at the stack trace the test gave me, and luckily it showed the exact line number/file it happened in.

nsCOMPtr<nsIDOMNode> targetNode(do_QueryInterface(aTarget));
nsCOMPtr<nsIDOMNode> parentNode;
targetNode->GetParentNode(getter_AddRefs(parentNode)); // This is going to crash if targetNode is NULL.

Therefore, before targetNode is deferenced, I had to check for targetNode being NULL, just a simple

if (!targetNode) return false;

I rebuilt and tested for the same thing, and now it doesn’t crash.

Hooray for testing!

From → Open Source

Leave a Comment

Leave a comment