Thread overview
-nan problem???
Dec 11, 2008
Sheridan
Dec 11, 2008
Denis Koroskin
Dec 12, 2008
Sheridan
Dec 12, 2008
Sheridan
December 11, 2008
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.
December 11, 2008
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' :)
                             ^^
December 12, 2008
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.


December 12, 2008
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.