Sign in to follow this  
belfegor

Effect error in debug mode

Recommended Posts

I got this error when i run my app in debug mode:

 

[quote]

effect.fx... error X3074: "BonesMats": implicit array missing initial value

[/quote]

 

witch i don't understand why it is happening and how to resolve it.

 

Here are my details:

[code]#define MAX_BONES_MATRICES     40 ... // and i create effect from file with this macros D3DXMACRO effMacros[2];
        effMacros[0].Name       = "MAX_BONES_MATRICES";
        effMacros[0].Definition = to_string(MAX_BONES_MATRICES).c_str();
        effMacros[1].Name       = nullptr;
        effMacros[1].Definition = nullptr;

        LPD3DXBUFFER effectsErrors = NULL;
        hr = D3DXCreateEffectFromFile(
            device, fxFileName.c_str(), &effMacros[0],
            nullptr, 0, nullptr, &effect, &effectsErrors);
        if(FAILED(hr)) ...[/code]

 

and in effect file i have this declaration that he is complaining about:

[code]... float4x4 BonesMats[MAX_BONES_MATRICES];[/code]

 

What am i missing?

Thank you for your time.

Share this post


Link to post
Share on other sites

2 things I'd try...

1) Instead of:

effMacros[0].Definition = to_string(MAX_BONES_MATRICES).c_str();

 

Try:

effMacros[0].Definition = "40";

 

2) Is it a compile time error? If it's happening at runtime, make sure you are sending 40 matrices to the effect before rendering

Edited by Nyssa

Share this post


Link to post
Share on other sites

I dont understand why this is happening?

 

[code]MessageBox(0, to_string(MAX_BONES_MATRICES).c_str(), 0, MB_OK); // message box says 40
        effMacros[0].Definition = "40";//to_string(MAX_BONES_MATRICES).c_str(); // but wont work here WTF?[/code]

Share this post


Link to post
Share on other sites

So this worked?

effMacros[0].Definition = "40";

 

The reason you would be seeing errors here is because "to_string" is returning a local variable (I'm guessing)  hence the string maybe destroyed after leaving the function "to_string".

So the reason it's working for the Message Box maybe just luck.

Edited by Nyssa

Share this post


Link to post
Share on other sites

effMacros[0].Definition = std::to_string(MAX_BONES_MATRICES).c_str();

the lifetime of return constant character string is owned by class string, which has limited scope in your code( no persistent variable
is available of class string) ,you'd better to use code explained by Nyssa

 

std::string boneMatixString = to_string(MAX_BONES_MATRICES)

effMacros[0].Definition = boneMatixString.c_str();

Edited by Anoop Chauhan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this