Directx driver effects double precision

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
drewbacca
Posts: 38
Joined: Tue Jan 30, 2007 6:49 pm

Directx driver effects double precision

Post by drewbacca »

I am having a problem where using directx in the Irrlicht device is changing the precision of math using doubles. The math results aren't used for the position of anything and is completely unrelated to video. Below I have a simple example where i add a small amount to a larger number (the result is well within double precision). Doing this before or after creating the irrlicht device changes the results if I use directx. I have verified this with the debugger as well as just cout. I am using the Irrlicht 1.2 release with visual studio2005 on winXP64 (though everything im doing is 32bit). In the process of typing this up, i have also noticed that problems only happen when optimizations are disabled. If optimizations are enabled, it works.

An example:

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;
using namespace std;

#pragma comment(lib, "Irrlicht.lib")


int main()
{

	double bigNum = 4304763.0;
	double smallNum = 0.1;
	double answer = bigNum+smallNum;

	cout.precision(12);
	cout << answer<<endl;


	IrrlichtDevice *device = device = createDevice(video::EDT_DIRECT3D8, core::dimension2d<s32>(800, 600), 16, false, false, false, 0);
	//IrrlichtDevice *device = device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600), 16, false, false, false, 0);

	double bigNum2 = 4304763.0;
	double smallNum2 = 0.1;
	double answer2 = bigNum2+smallNum2;


	cout.precision(12);
	cout << answer2<<endl;

	return 0;
}
The code before createDevice calculates the correct answer, while the same code below does not. Changing the video driver to openGL fixes this problem, but I would like to use directx if possible. What is really weird, is that this problem only occurs when VS's optimizations are disabled. Things work fine if the code is optimized for speed.


Is this a bug in Irrlicht or something I don't understand about Visual studio?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

This is a DirectX feature which you can avoid by setting the according flag in the Irrlicht parameters at device creation. Set HighPrecisionFPU to true.
drewbacca
Posts: 38
Joined: Tue Jan 30, 2007 6:49 pm

Post by drewbacca »

Thank you. I was only looking at createDevice and hadn't looked at the extra parameters set in createDeviceEx.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Don't forget the Windows "feature" where the floating-point control word gets reset by loading a dll. I forget the specifics, but a search on MSDN should uncover the details.
Post Reply