www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - -nan problem???

reply Sheridan <superpeti freemai.hu> writes:
Hi!

I am new in D language. I implement a little 2D/3D engine, and during the
development I faced an interesting problem.

I have this function:

 void addBackgroundToLayer2(char[] textureName, float posx, float posy)
    {
        CTexture tex = new CTexture(textureName); //create the texture

        tex.m_itexurePosX = posx;
        tex.m_itexurePosY = posy;
       
        writefln("X: %f, Y: %f", tex.m_itexurePosX,tex.m_itexurePosY);

        m_Layer2~=tex;
    }

The problem is that the value of tex.m_itexurePosX variable will be "-nan". But
value of posx is good.

If I change the sort of the lines:

 void addBackgroundToLayer2(char[] textureName, float posx, float posy)
    {
        CTexture tex = new CTexture(textureName);

        m_Layer2~=tex;

        tex.m_itexurePosX = posx;
        tex.m_itexurePosY = posy;
       
        writefln("X: %f, Y: %f", tex.m_itexurePosX,tex.m_itexurePosY);
    }

Then everything works fine. What do I wrong? I do not understand this problem.
I use dmd 1.037 compiler. 
Dec 11 2008
parent reply "Denis Koroskin" <2korden gmail.com> writes:
On Fri, 12 Dec 2008 02:26:55 +0300, Sheridan <superpeti freemai.hu> wrote:

 Hi!

 I am new in D language. I implement a little 2D/3D engine, and during  
 the development I faced an interesting problem.

 I have this function:

  void addBackgroundToLayer2(char[] textureName, float posx, float posy)
     {
         CTexture tex = new CTexture(textureName); //create the texture

         tex.m_itexurePosX = posx;
         tex.m_itexurePosY = posy;
        writefln("X: %f, Y: %f", tex.m_itexurePosX,tex.m_itexurePosY);

         m_Layer2~=tex;
     }

 The problem is that the value of tex.m_itexurePosX variable will be  
 "-nan". But value of posx is good.

 If I change the sort of the lines:

  void addBackgroundToLayer2(char[] textureName, float posx, float posy)
     {
         CTexture tex = new CTexture(textureName);

         m_Layer2~=tex;

         tex.m_itexurePosX = posx;
         tex.m_itexurePosY = posy;
        writefln("X: %f, Y: %f", tex.m_itexurePosX,tex.m_itexurePosY);
     }

 Then everything works fine. What do I wrong? I do not understand this  
 problem. I use dmd 1.037 compiler.

Looks like a bug. Could you please provide a compilable code sample (small one, if possible) so that we could reproduce it? BTW, you have a typo in 'm_itexurePosX' :) ^^
Dec 11 2008
next sibling parent Sheridan <superpeti freemail.hu> writes:
Ok, I try to post a small code. But I have about 40 files and they are not
public. But i will make a small piece of the code to reproduce the problem. 
Dec 11 2008
prev sibling parent Sheridan <superpeti freemail.hu> writes:
Hi!

I have created a sample code to show my "-nan" problem. It is not the cleanest
code :-), but I do not want to delete a lot from the problematic files.

I realized, that the problem appears only when the compiler "Optimize" flag is
enabled.

I use Derelict and Codeblocks. You can also download the code here:

http://compaq.iit.uni-miskolc.hu/d/SampleBug.zip

Thanks for reply.
Dec 12 2008