Skip to main content
GameDev.net gamedev.net
🔒 Locked

Effect error in debug mode

Started by belfegor Jan 6, 2013 at 12:23 AM 5 replies 1.9k views
Original Post
belfegor
belfegor

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.

Helo7777
Helo7777

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

belfegor
belfegor

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?

Helo7777
Helo7777

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.

belfegor
belfegor

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?

Anoop Chauhan
Anoop Chauhan

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.