Search code examples
c++pythondirect3dembeddingogre3d

Can't modify value returned by time.time() in Python code embedded in C++


I'm facing a very strange problem.

The following code:

import time
target_time = time.time() + 30.0

doesn't work in Python code called from C++ (embedding)!

target_time has the same value as time.time() and any attempt to modify it leaves the value unchanged in a pdb console...

alt text http://dl.dropbox.com/u/3545118/time_bug.png

It happens after I've called root.initialise() in Ogre3D graphics engine, but only when using Direct3D, not when using OpenGL.

So this might be related to Direct3D...


Solution

  • Found the answer in that thread: http://www.ogre3d.org/forums/viewtopic.php?f=1&t=55013&p=373940&hilit=D3DCREATE_FPU_PRESERVE#p373940

    http://msdn.microsoft.com/en-us/library/ee416457%28VS.85%29.aspx

    D3DCREATE_FPU_PRESERVE Set the precision for Direct3D floating-point calculations to the precision used by the calling thread. If you do not specify this flag, Direct3D defaults to single-precision round-to-nearest mode for two reasons:

    • Double-precision mode will reduce Direct3D performance.
    • Portions of Direct3D assume floating-point unit exceptions are masked; unmasking these exceptions may result in undefined behavior.