我正在使用DirectX处理图形引擎。我简化了这样的一个功能(因为它有同样的问题):
void foo(int p,int q){
if(!p){
int a=0;
a=4;
}else{
int a=0;
a=5;
}
if(p==1){
if(q==1){
float opacity=0;
}
}
}
int main(){
foo(1,2);
return 0;
}
如果我调用foo(1,2),我无法在VS Debug面板中查看in块中的值,但是当我调用foo(0,2)时,我可以看到if中的a的值。它显示符号'a'找不到bla bla ...当我改变了“float opacity = 0;” “漂浮不透明;”它运作良好,我可以调试它。
我根据属性对对象,网格和材质进行分组。这是我原来的功能:
VOID DXACMyApp::LoadSceneFromFile(CHAR *a_file){
//File name can not be null
DXAMIsNull(a_file,DXAE_ERROR_REPORTING_LEVEL_MBOX);
DXAMIsNull(m_effect,DXAE_ERROR_REPORTING_LEVEL_MBOX);
//Create Supported Input Layouts
//1st input layout
//elements
D3D11_INPUT_ELEMENT_DESC ied_PN[] = {
{"POSITION", 0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0},
{"NORMAL", 0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0}
};
//every pass of same technique must have same layout
//create input layout
IDXACRenderGroupIL *ilGroup_PN = 0;
DXAMHResult(CreateILGroup(m_effect->GetTechniqueByName("SolidMaterialRender"),ied_PN,2,&ilGroup_PN),DXAE_ERROR_REPORTING_LEVEL_MBOX);
AddInputLayoutGroup(ilGroup_PN);
//create technique groups
IDXACRenderGroupTechnique *SolidMaterialTechGroup = 0;
DXAMHResult(CreateTechniqueGroup(m_effect->GetTechniqueByName("SolidMaterialRender"),&SolidMaterialTechGroup),DXAE_ERROR_REPORTING_LEVEL_MBOX);
//add tech group to il group
ilGroup_PN->AddTechniqueGroup(SolidMaterialTechGroup);
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(a_file,aiProcess_CalcTangentSpace|aiProcess_Triangulate|aiProcess_OptimizeMeshes|
aiProcess_JoinIdenticalVertices|aiProcess_SortByPType|aiProcess_RemoveRedundantMaterials);
//iterate objects
for(UINT i=0 ; i<scene->mRootNode->mNumChildren ; i++){
aiNode *object = scene->mRootNode->mChildren[i];
D3DXMATRIX worldMatrix = ToD3DXMATRIX(object->mTransformation);
//object's mesh vector
std::vector<IDXACMesh*> meshes;
//count known mesh types
UINT recognizedMeshCount = 0;
//iterate object's meshes(materials)
for(UINT j=0 ; j<object->mNumMeshes ; j++){
aiMesh *mesh = scene->mMeshes[ object->mMeshes[j] ];
//Test material type
aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex];
BOOL recognized = false;
IDXACMaterial *newMaterial = 0;
if(material->mNumProperties == 8){
//materials with 8 properties
if( strcmp(material->mProperties[0]->mKey.data,"?mat.name")==0 &&
strcmp(material->mProperties[1]->mKey.data,"$clr.ambient")==0 &&
strcmp(material->mProperties[2]->mKey.data,"$clr.diffuse")==0 &&
strcmp(material->mProperties[3]->mKey.data,"$clr.specular")==0 &&
strcmp(material->mProperties[4]->mKey.data,"$clr.emissive")==0 &&
strcmp(material->mProperties[5]->mKey.data,"$mat.opacity")==0 &&
strcmp(material->mProperties[6]->mKey.data,"$mat.bumpscaling")==0 &&
strcmp(material->mProperties[7]->mKey.data,"$mat.shadingm")==0 ){
FLOAT opacity,specPower;
D3DXCOLOR diffuse;
D3DXCOLOR specular,ambient,emissive;
//get material info
specPower = 1.0f;
memcpy(&ambient ,material->mProperties[1]->mData,12);
memcpy(&diffuse ,material->mProperties[2]->mData,12);
memcpy(&specular,material->mProperties[3]->mData,12);
memcpy(&emissive,material->mProperties[4]->mData,12);
memcpy(&opacity ,material->mProperties[5]->mData,4);
diffuse.a = ambient.a = specular.a = emissive.a = opacity;
//create material interface
std::string matName(material->mProperties[0]->mData,17);
DXACMaterialT1 *matInstance = 0;
matInstance = new DXACMaterialT1(material->mProperties[0]->mData,&diffuse,&specular,&ambient,&emissive,specPower,m_effect);
newMaterial = matInstance;
recognized = true;
recognizedMeshCount++;
}
}else if(material->mNumProperties == 10){
if( strcmp(material->mProperties[0]->mKey.data,"?mat.name")==0 &&
strcmp(material->mProperties[1]->mKey.data,"$clr.ambient")==0 &&
strcmp(material->mProperties[2]->mKey.data,"$clr.diffuse")==0 &&
strcmp(material->mProperties[3]->mKey.data,"$clr.specular")==0 &&
strcmp(material->mProperties[4]->mKey.data,"$clr.emissive")==0 &&
strcmp(material->mProperties[5]->mKey.data,"$mat.shininess")==0 &&
strcmp(material->mProperties[6]->mKey.data,"$mat.shinpercent")==0 &&
strcmp(material->mProperties[7]->mKey.data,"$mat.opacity")==0 &&
strcmp(material->mProperties[8]->mKey.data,"$mat.bumpscaling")==0 &&
strcmp(material->mProperties[9]->mKey.data,"$mat.shadingm")==0 ){
D3DXCOLOR diffuse;
D3DXCOLOR specular,ambient,emissive;
FLOAT opacity,specPower;
memcpy(&ambient ,material->mProperties[1]->mData,12);
memcpy(&diffuse ,material->mProperties[2]->mData,12);
memcpy(&specular,material->mProperties[3]->mData,12);
memcpy(&emissive,material->mProperties[4]->mData,12);
memcpy(&specPower ,material->mProperties[5]->mData,4);
memcpy(&opacity ,material->mProperties[7]->mData,4);
diffuse.a = ambient.a = specular.a = emissive.a = opacity;
std::string matName(material->mProperties[0]->mData,17);
DXACMaterialT1 *matInstance = new DXACMaterialT1(matName.substr(4,matName.npos).c_str(),&diffuse,&specular,&ambient,&emissive,specPower,m_effect);
newMaterial = matInstance;
recognized = true;
recognizedMeshCount++;
}
}
if(recognized){
//create mesh instance
DXACMeshT1 *newMesh = new DXACMeshT1(m_d3dDeviceContext);
//fill vertex buffer desc
D3D11_BUFFER_DESC vbd;
vbd.ByteWidth = mesh->mNumVertices*sizeof(VERTEXT1);
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
vbd.StructureByteStride = 0;
vbd.Usage = D3D11_USAGE_IMMUTABLE;
//create vertex buffer memory block and subres. data
VERTEXT1 *vbMemBlock = new VERTEXT1[mesh->mNumVertices];
for(UINT i=0; i<mesh->mNumVertices ; i++){
vbMemBlock[i] = VERTEXT1(mesh->mVertices[i],mesh->mNormals[i]);
}
D3D11_SUBRESOURCE_DATA vbSrd;
vbSrd.pSysMem = vbMemBlock;
DXAMHResult(m_d3dDevice->CreateBuffer(&vbd,&vbSrd,&newMesh->m_vertexBuffer),DXAE_ERROR_REPORTING_LEVEL_MBOX);
newMesh->m_vertexCount = mesh->mNumVertices;
newMesh->m_vertexStride = sizeof(VERTEXT1);
//fill index buffer desc
//only triangles are valid as face
D3D11_BUFFER_DESC ibd;
ibd.ByteWidth = mesh->mNumFaces*3*sizeof(DWORD);
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
ibd.StructureByteStride = 0;
ibd.Usage = D3D11_USAGE_IMMUTABLE;
//create index buffer memory block and subres. data
DWORD *ibMemBlock = new DWORD[mesh->mNumFaces*3];
for(UINT i=0,j=0; i<mesh->mNumFaces ; i++){
aiFace &face = mesh->mFaces[i];
if(face.mNumIndices!=3){
OutputDebugString("Ignoring face");
ibMemBlock[j++] = 0;
ibMemBlock[j++] = 0;
ibMemBlock[j++] = 0;
}else{
ibMemBlock[j++] = face.mIndices[0];
ibMemBlock[j++] = face.mIndices[1];
ibMemBlock[j++] = face.mIndices[2];
}
}
D3D11_SUBRESOURCE_DATA ibSrd;
ibSrd.pSysMem = ibMemBlock;
DXAMHResult(m_d3dDevice->CreateBuffer(&ibd,&ibSrd,&newMesh->m_indexBuffer),DXAE_ERROR_REPORTING_LEVEL_MBOX);
newMesh->m_indexCount = mesh->mNumFaces*3;
IDXACMesh *imesh = newMesh;
imesh->Release();
}else{
//not recognized material
OutputDebugString("Ignoring mesh");
return;
}
}
}
ReleaseCOM(SolidMaterialTechGroup);
ReleaseCOM(ilGroup_PN);
}
答案 0 :(得分:0)
在else中,超出了您感兴趣的变量的范围。 将变量移到函数的顶部,它们将具有函数范围, 允许您在调试器中查看它们以了解整个函数的范围
void foo(int p,int q)
{
int a = 0; // Move them here
float opacity = 3.1415f; // And here
if(!p)
{
a=4;
}
else
{
a=5;
}
if(p==1)
{
if(q==1)
{
opacity=0;
}
}
}
int main()
{
foo(1,2);
return 0;
}
答案 1 :(得分:0)
这是VS 2010中的一个错误。我刚刚安装了VS SP1,我可以在不修改代码的情况下调试任何变量。