• Advertisement
Sign in to follow this  

Effect error in debug mode

This topic is 1843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

 

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:

#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)) ...

 

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

... float4x4 BonesMats[MAX_BONES_MATRICES];

 

What am i missing?

Thank you for your time.

Share this post


Link to post
Share on other sites
Advertisement

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?

 

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?

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

to_string returns string copy not a reference to a local, and c_str() function returns const char* as this "40" literal type should be!!!

There is something strange happening, black magic?

Share this post


Link to post
Share on other sites
So it's returning a std::string?
Then try this:
 
std::string boneMatixString = to_string(MAX_BONES_MATRICES);
effMacros[0].Definition = boneMatixString.c_str();

 

 

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
Sign in to follow this  

  • Advertisement