Edit:4
I solved it now I think for good.
I removed every xmmatrix and replaced it with XMFLOAT4x4 and I just use xmstore and xmload to transfer the values.
Edit:
Got it to work with the string now after I restarted the compiler but now xnamath give me access violation if I DON'T have the string instead
Edit 2:
Nope, Restared it once again now am back to square one, give me the error if I HAVE the string decalred
am getting more and more confuse for each restart I do
Edit3
After some more experimenting, xnamath will complain on string depending on whenever it was declared the moment I open the compiler or not.
Example:
If I have the string declared when I start the compiler it will work, but will start to complain whenever I try to remove it/comment out it.
Can someone explain to me whats going on O.O?????
Hi,
For I been trying to figure out why I get xnamath crashes, And after along time and many sacrificed backups I found it.
I have a header file called hA which look like this
#ifndef ModelClass_H#define ModelClass_H#include #include #include #include struct VertexStruct //Overloaded Vertex Structure{ VertexStruct(){} VertexStruct(float x, float y, float z,float u, float v,float nx,float ny,float nz ): Position(x,y,z), UVCordinate(u, v),Normal(nx,ny,nz){} XMFLOAT3 Position; XMFLOAT2 UVCordinate; XMFLOAT3 Normal;};struct FaceStruct{ int vIndex1, vIndex2, vIndex3; int tIndex1, tIndex2, tIndex3; int nIndex1, nIndex2, nIndex3;};class ModelHandler{ struct TotalCount { int Face; int Triangle; int Normal; int Vertex; int Test; };public: ModelHandler() { Reset(); } void Reset(); TotalCount Total; std::string bla; <--------------------CRASH if I try to define string here};#endif.h>.h>.h>
and I have another cpp file called cppA and header file called hB that is TOTAL UNRELATED (for now) and either cppA or hB is using ANYTHING from hA.
cppA file look like this
#include #include #include "ObjectH.h"#include "RenderComponentH.h"#include "DirectXHandlerH.h"#include "CameraHandlerH.h"#include bool RenderComponent::Initializing(){ ID3D11Device* pD3d11Device; pD3d11Device = Get3DDevice(); Vertex* pVertices; pVertices = new Vertex[5]; Vertex v[] = { // Front Face Vertex(-1.0f, -1.0f, -1.0f, 0.0f, 1.0f), Vertex(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f), Vertex( 1.0f, 1.0f, -1.0f, 1.0f, 0.0f), Vertex( 1.0f, -1.0f, -1.0f, 1.0f, 1.0f), // Back Face Vertex(-1.0f, -1.0f, 1.0f, 1.0f, 1.0f), Vertex( 1.0f, -1.0f, 1.0f, 0.0f, 1.0f), Vertex( 1.0f, 1.0f, 1.0f, 0.0f, 0.0f), Vertex(-1.0f, 1.0f, 1.0f, 1.0f, 0.0f), // Top Face Vertex(-1.0f, 1.0f, -1.0f, 0.0f, 1.0f), Vertex(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f), Vertex( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f), Vertex( 1.0f, 1.0f, -1.0f, 1.0f, 1.0f), // Bottom Face Vertex(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f), Vertex( 1.0f, -1.0f, -1.0f, 0.0f, 1.0f), Vertex( 1.0f, -1.0f, 1.0f, 0.0f, 0.0f), Vertex(-1.0f, -1.0f, 1.0f, 1.0f, 0.0f), // Left Face Vertex(-1.0f, -1.0f, 1.0f, 0.0f, 1.0f), Vertex(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f), Vertex(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f), Vertex(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f), // Right Face Vertex( 1.0f, -1.0f, -1.0f, 0.0f, 1.0f), Vertex( 1.0f, 1.0f, -1.0f, 0.0f, 0.0f), Vertex( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f), Vertex( 1.0f, -1.0f, 1.0f, 1.0f, 1.0f), }; DWORD indices[] = { // Front Face 0, 1, 2, 0, 2, 3, // Back Face 4, 5, 6, 4, 6, 7, // Top Face 8, 9, 10, 8, 10, 11, // Bottom Face 12, 13, 14, 12, 14, 15, // Left Face 16, 17, 18, 16, 18, 19, // Right Face 20, 21, 22, 20, 22, 23 }; //Create the vertex buffer D3D11_BUFFER_DESC indexBufferDesc; ZeroMemory( &indexBufferDesc, sizeof(indexBufferDesc) ); indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(DWORD) * 12 * 3; indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = indices; pD3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &Buffer.Model.pIndexBuffer); //Create the vertex buffer Describer and describ it D3D11_BUFFER_DESC vertexBufferDesc; ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) ); vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof( Vertex ) * 24; //vertexBufferDesc.ByteWidth = sizeof( Vertex ) * Model.VertexCount; vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vertexBufferData; ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) ); vertexBufferData.pSysMem = v; pD3d11Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &Buffer.Model.pVertexBuffer); delete [] pVertices; pVertices = 0; HRESULT hr; D3D11_BUFFER_DESC cbbd; ZeroMemory(&cbbd, sizeof(D3D11_BUFFER_DESC)); cbbd.Usage = D3D11_USAGE_DEFAULT; cbbd.ByteWidth = sizeof(ConstantRenderBuffer); cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbbd.CPUAccessFlags = 0; cbbd.MiscFlags = 0; hr = pD3d11Device->CreateBuffer(&cbbd, NULL, &Buffer.Model.pcObjectBuffer); RenderState = GetWireFrameState(); return true;}bool RenderComponent::Special(){ ID3D11DeviceContext* pD3d11DevCon; pD3d11DevCon = Get3DDevCon(); UINT stride = sizeof( Vertex ); UINT offset = 0; //Set the vertex pD3d11DevCon->IASetIndexBuffer(Buffer.Model.pIndexBuffer, DXGI_FORMAT_R32_UINT, 0); pD3d11DevCon->IASetVertexBuffers( 0, 1, &Buffer.Model.pVertexBuffer, &stride, &offset ); //Set Correct Model Buffer pD3d11DevCon->UpdateSubresource(Buffer.Model.pcObjectBuffer, 0, NULL, &Buffer.cBufferObject, 0, 0 ); pD3d11DevCon->VSSetConstantBuffers( 0, 1, &Buffer.Model.pcObjectBuffer); //Set Texture pD3d11DevCon->PSSetShaderResources( 0, 1, &Buffer.Texture.Diffuse.Texture ); pD3d11DevCon->PSSetSamplers( 0, 1, &Buffer.Texture.Diffuse.Sampler ); pD3d11DevCon->RSSetState(NULL); pD3d11DevCon->DrawIndexed(36,0,0); //Set Vertex and Pixel Shaders //pD3d11DevCon->VSSetShader(Shader.VS, 0, 0); //pD3d11DevCon->PSSetShader(Shader.PS, 0, 0); return true; }void RenderComponent::Update(){ TransformComponent tTransformComponent; TransformMatrix tMatrixTransform; pHolder->ComponentList["TransformComponent"]->getMe(tTransformComponent); tMatrixTransform.LocalPosition = XMLoadFloat4x4(&tTransformComponent.Transform.LocalPosition); tMatrixTransform.Rotation = XMLoadFloat4x4(&tTransformComponent.Transform.Rotation); tMatrixTransform.Scale = XMLoadFloat4x4(&tTransformComponent.Transform.Scale); tMatrixTransform.WorldPosition= XMLoadFloat4x4(&tTransformComponent.Transform.WorldPosition); if(true) { Camera* pTheCamera; pTheCamera = GetCamera(); //Reset The Position(Still not sure if its Local or world or whatever) //tMatrixTransform.LocalPosition = XMMatrixIdentity(); //tMatrixTransform.Translation = XMMatrixTranslation( 0.0f, 0.0f, 4.0f ); //Set cube1's world space using the transformations tMatrixTransform.WorldPosition = tMatrixTransform.LocalPosition * tMatrixTransform.Scale * tMatrixTransform.Rotation; tMatrixTransform.WorldPosition = tMatrixTransform.LocalPosition * pTheCamera->View * pTheCamera->Projection;Buffer.cBufferObject.WVP = XMMatrixTranspose(tMatrixTransform.WorldPosition); <---------THIS ONE is the one that CRASH } else { MessageBox(NULL,"The Entity Object has no Transform Component you sure this is correct?","Error",MB_OK); }}void RenderComponent::Destroy(){ Buffer.Model.pIndexBuffer->Release(); Buffer.Model.pVertexBuffer->Release(); Buffer.Model.pcObjectBuffer->Release(); Buffer.Texture.Diffuse.Sampler->Release(); Buffer.Texture.Diffuse.Texture->Release(); //RenderState->Release(); //Buffer.Lightning.pVSBuffer->Release(); //Buffer.Lightning.pPSBuffer->Release();}void RenderComponent::setHolder(Entity* _pHolder){ pHolder = _pHolder; MessageBox(0,"It Works","Yay",MB_OK); }void RenderComponent::getMe(Buffers& pRender){ pRender = Buffer;}bool RenderComponent::LoadTexture(){ HRESULT hr; ID3D11Device* pD3d11Device; pD3d11Device = Get3DDevice(); hr = D3DX11CreateShaderResourceViewFromFile(pD3d11Device ,Buffer.Texture.Diffuse.Location.c_str(),NULL, NULL, &Buffer.Texture.Diffuse.Texture, NULL ); if(FAILED(hr)) { MessageBox(0,DXGetErrorDescription(hr),"Error",MB_OK); } D3D11_SAMPLER_DESC sampDesc; ZeroMemory( &sampDesc, sizeof(sampDesc) ); sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; sampDesc.MinLOD = 0; sampDesc.MaxLOD = D3D11_FLOAT32_MAX; pD3d11Device->CreateSamplerState(&sampDesc,&Buffer.Texture.Diffuse.Sampler); return true;}std::string RenderComponent::getTypeName(){ return typeName;}.h>.h>.h>
while hB look like
#ifndef RenderComponent_H#define RenderComponent_H#include #include #include #include #include "BaseComponentH.h"#include "EntityHandlerH.h"#include "TransformComponentH.h"struct ConstantRenderBuffer{ XMMATRIX WVP;};struct Buffers{ struct ModelBuffer { ID3D11Buffer* pVertexBuffer; ID3D11Buffer* pIndexBuffer; ID3D11Buffer* pcObjectBuffer; }; struct LightningBuffer { ID3D10Blob* pVSBuffer; ID3D10Blob* pPSBuffer; }; struct TextureBuffer { struct DiffuseObjects { ID3D11ShaderResourceView* Texture; ID3D11SamplerState* Sampler; std::string Location; }; DiffuseObjects Diffuse; }; ModelBuffer Model; TextureBuffer Texture; LightningBuffer Lightning; ConstantRenderBuffer cBufferObject;};class RenderComponent: public BaseComponent{private: public: RenderComponent() { typeName = "RenderComponent"; Buffer.Texture.Diffuse.Location = "Test.jpg"; LoadTexture(); Initializing(); } RenderComponent(Entity* pComponentHolder) { typeName = "RenderComponent"; pHolder = pComponentHolder; } ~RenderComponent(){} bool Initializing(); bool Special(); void Update(); void Destroy(); void setHolder(Entity* _pHolder); void getMe(Buffers& pRender); bool LoadTexture(); std::string getTypeName(); std::string typeName; ID3D11RasterizerState* RenderState; Buffers Buffer; Entity* pHolder;};#endif.h>.h>.h>
and I have a main.cpp
that which call upon the RenderComponent.Update()
If I dont declare std::string inside hA header, Everything work as it should be.
but If I try to declare std::string inside the header
XMMatrixTranspose do not work after I declare and just crash upon reaching that line.
but the program will work if I just comment/remove the line. but why would it crash in the first place?