Effect error in debug mode

Started by
5 comments, last by Anoop Chauhan 11 years, 3 months ago

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.

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

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?

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.

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?

So it's returning a std::string?
Then try this:

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

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();

This topic is closed to new replies.

Advertisement