So, I had the same issue, although I didn't set the ROS_MASTER_URI
globally.
I managed to get around this specific issue by adding
ROS_MASTER_URI=http://localhost:11311
to the debugging environment variables (Project->Properties->Configuration Properties->Debugging->Environment).
However, after implementing the above I got an uncaught exception (Unhandled exception at 0x768bc41f in ros_demo.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0028f0e4..
).
That went away when I built, compiled and ran the project in release mode (which matched my ROS SDK build).
I got the idea for the release/debug build from here:
xstring isn't an OSG specific object, so the error is elsewhere in the 3rd party dependency chain. As I know nothing about your OS and software setup I can't speculate what this might be.
In general though this type of error could well be a linking issue - for instance Visual Studio is hopeless at handling different libs being built debug and release and will crash randomly.
That was fun to discover..