Sign in to follow this  
Conny14156

xnamath access violation because of std::string variable

Recommended Posts

Conny14156    279

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 sad.png

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?

Share this post


Link to post
Share on other sites
__SKYe    1784

Don't really know if i can help, but try changing the order of the includes, for example, try including <string> before anything else, or after anything else... Seriously don't really know what the issue could be...

Share this post


Link to post
Share on other sites
Conny14156    279

Nope doesn't work :(, still give me acess violation error :/. 

P.S

hB have nothing to do with hA. so I don't think it could be anything with the include order :( 

Share this post


Link to post
Share on other sites
Conny14156    279
I got it partly working now by restarting the compiler.
But am still very confuse why xnamath gave me access violation (and still give) if I try to change the string o.o? if I don't rebuild it, even tho neither headers /cpp have anything to do with each other.
I should had tried to rebuild it before I posted here >.< sorry for wasting the time


Edited
PS
Now xnamath give's me the error if I don't have the string declared o.o

Edit2:
PS2

Back to square one after restarting again, give me the error when I HAVE the string declared Edited by Conny14156

Share this post


Link to post
Share on other sites
yckx    1298

It's difficult to go through your code on my phone, but it sounds like things that can happen if an XMMATRIX isn't aligned in memory. Is the variable you're writing to allocated on the heap? Or owned by an object that is allocated on the heap?

 

 

 

Edit: taking another look at it, I'm guessing your RenderComponent object is heap allocated. XMMATRIX needs to be 16 bit aligned in memory. If it's on the stack then it's pretty much done for you, due to how XMMATRIX is defined. But on the heap, you have to make sure it's properly aligned yourself. When I have a chance to get on my pc I can post some links that can explain how to deal with this, but you can be proactive and google "heap aligned memory" or something similar. I remember there's a gamasutra article that explains it quite well.

Edited by yckx

Share this post


Link to post
Share on other sites
Conny14156    279

Am sorry, iam still not that advance with c++ yet, so am not 100% sure what heap mean :x,

but if you mean about the xmmatrix if its allign to 16byte or not. it should be, as load the value from a xmfloat into a xmmatrix. to avoid that problem (I had it once before >.<)

oh but the xmmatrix is inside a struct, but I declare it inside the function. 

Share this post


Link to post
Share on other sites
__SKYe    1784

Try having the string declared but comment the XNMatrixTranspose line and see if it crashes.

 

If it doesn't, instead of performing the XNMatrixTranspose operation like this

 

Buffer.cBufferObject.WVP = XMMatrixTranspose(tMatrixTransform.WorldPosition);

try it like this

 

XMMatrixTranspose(tMatrixTransform.WorldPosition);

 

it's just to see if it crashes.

 

Again, i'm as lost as you on this, but keep trying and say something.

Share this post


Link to post
Share on other sites
Conny14156    279

Already tested with commenting out the Transpose when I had the string, it does indeed not crash

and just tested out the XMMatrixTranspose without assigning it to the buffer, it does indeed not crash.

So am guessing it has something to do with my buffer o.o? but why? and HOW O.O?

Share this post


Link to post
Share on other sites
yckx    1298

The heap is the part of memory where dynamically declared objects live. So, anything created with "new". It looks like the XMMATRIX you're writing to is a member of a strict that's a member of a RenderComponent object. If you created that object with "new" then that's what's throwing you off.

Share this post


Link to post
Share on other sites
__SKYe    1784

The problem seem to be with Buffer.cBufferObject.WVP, but i can't be sure. Do you use somewhere else? Did you try to initialize it?

 

Try changing in in some other place, like the Initialize function, and see if it works.

 

ALso can you post the exact error messages you get?

Don't know if it will make a difference, but everything helps.

Share this post


Link to post
Share on other sites
Conny14156    279

Nope, thats the only place I use it, and no matter were I put it seems like it doesn't give me access to that variable o.o,

 

 

Unhandled exception at 0x01132f9c in FusionEmpty.exe: 0xC0000005: Access violation reading location 0x00000000.

and this is the access violation error.

And I don't really think its only about my Buffer.cBufferObject.WVP, as it works aslong I started my program correct.

like if I want to use the string I need to have it written before I start the compiler and vice versa ;(

Share this post


Link to post
Share on other sites
__SKYe    1784

Ok i'm gonna throw a couple things that probably have nothing to do/won't do anything.

 

First, try to comment the std::string line, and replace it with another variable, like "int bla;", and check if it crashes

 

Second, instead of "std::string bla", use a pointer "std::string *bla", again check if it works

 

Right now, i'm inclined to think that the problem isn't with the matrix. Maybe the declaration on that string changes something somewhere else, and it doesn't necessarily mean that the real problem is the string, i mean, a std::string preventing a matrix operation from working?

 

Well, probably won't help much, but try it out...

Share this post


Link to post
Share on other sites
Conny14156    279

Well,

after I few expriment including what you guys suggested :3

am now stuck with the string, aka I can't comment it out/remove it without my program crashes.

 

Btw

I had a copy of the program when the problem first upstood.

I tested with a int and a string pointer both worked but not if its a string

But that was in the first problem version.

 

Kinda confusing but the problem now is that I can't remove the string >.<

 

P.S

the string does NOTHING, its just there.

Share this post


Link to post
Share on other sites
__SKYe    1784

Well, sorry i can't be of more help.

Since other variables work(ed), the problem probably isn't the string per se. It must be somewhere else, although i have no clue as to where.

 

If you have anymore news, let us now and maybe we can help more.

 

For now maybe try to use a regular "char *", if you can remove the string now, that is.

 

Good luck!

Share this post


Link to post
Share on other sites
Conny14156    279
Nope Can't remove it >.< altho tbh I rather can't remove than not have it as I needed it in the first place.
Am just very afraid to even use that header for now if its wanna do some other funny stuff >.>
and the thing am most worry about is that stupid constantBuffer, it always have something funny error it wanna share >.<

Edit:
Just tested a thing
I can't either remove it but can't have another string o.o

Am really considering remaking my project yet again >.<

Edit2:
I tried to add a wstring but it still complained,
I tried to change the first string (the one I couldt remove) into a wstring and it worked fine fine. am totally lost here ;(

Free digital Cookie for the one who can explain this Edited by Conny14156

Share this post


Link to post
Share on other sites
yckx    1298

Can you show the code that creates the RenderComponent instance(s)?

 

 

 

Also, you might want to try using an XMFLOAT4X4 instead of an XMMATRIX. It will require using XMLoadFloat4x4() and XMStoreFloat4x4() to convert to and from XMMATRIX for the functions that expect one as a parameter or return one, but if it is indeed an alignment problem, that should make it go away, since XMFLOAT4X4 needn't be aligned. This will cost you some in efficiency and code readability, but it should let you continue and revisit memory alignment when you're better prepared.

Share this post


Link to post
Share on other sites
Zaoshi Kaba    8434

As someone already said, please check if it's aligned properly.
How to do it:

  • Wait till it crashes and attach debugger to see where it happened
     
  • Once it happens (probably at Buffer.cBufferObject.WVP = XMMatrixTranspose(tMatrixTransform.WorldPosition); line) see what's the address of Buffer.cBufferObject.WVP and tMatrixTransform.WorldPosition, it should end with 0. If it ends with anything else (usually 8) then it's not aligned properly.

Would be nice if you could grab screenshot as proof, maybe there's something else as well.

Share this post


Link to post
Share on other sites
Conny14156    279
Can you show the code that creates the RenderComponent instance(s)?

 

 

 

Also, you might want to try using an XMFLOAT4X4 instead of an XMMATRIX. It will require using XMLoadFloat4x4() and XMStoreFloat4x4() to convert to and from XMMATRIX for the functions that expect one as a parameter or return one, but if it is indeed an alignment problem, that should make it go away, since XMFLOAT4X4 needn't be aligned. This will cost you some in efficiency and code readability, but it should let you continue and revisit memory alignment when you're better prepared.

 

Here the class that creates it

#ifndef FactoryComponent_H
#define FactoryComponent_H
class FactoryComponent
{
public:
	FactoryComponent(){}
	virtual ~FactoryComponent(){}

	template<class ComponentType>
	std::shared_ptr<ComponentType> ComponentInstantiate()
	{
		//Never Forget
		//std::make_shared<Type>() creates a std::shared_ptr pointing to a instance of 'Type'
		//that std::make_shared dynamically allocates for you (so no need to call 'new'). 
		//Zero or more arguments can be passed to std::make_shared, and are handed to Type's constructor. 
		
		return std::make_shared<ComponentType>();
	}
	template<class ComponentType>
	std::shared_ptr<ComponentType> ComponentInstantiate(std::string specialInput)
	{
		//Never Forget
		//std::make_shared<Type>() creates a std::shared_ptr pointing to a instance of 'Type'
		//that std::make_shared dynamically allocates for you (so no need to call 'new'). 
		//Zero or more arguments can be passed to std::make_shared, and are handed to Type's constructor. 
		
		return std::make_shared<ComponentType>(specialInput);
	}
};


#endif

And here how I call upon the function

bool InitMaster()
{
	//Real
	std::string Test;
	vEntity.push_back(eFactory.EntityInstantiate<Entity>());
	vEntity[0]->AddComponent(cFactory.ComponentInstantiate<TransformComponent>());
	vEntity[0]->AddComponent(cFactory.ComponentInstantiate<RenderComponent>());
	vEntity[0]->ComponentList["RenderComponent"]->setHolder(vEntity[0].get());

	return true;
}
void DrawEntity()
{
	vEntity[0]->ComponentList["RenderComponent"]->Update(); 
	vEntity[0]->ComponentList["RenderComponent"]->Special();
	





}

 

 

 

My render component the one that holds the object have this value when I check with debugger

0x00c45928

 

 

 

 

As someone already said, please check if it's aligned properly.
How to do it:
  • Wait till it crashes and attach debugger to see where it happened
     
  • Once it happens (probably at Buffer.cBufferObject.WVP = XMMatrixTranspose(tMatrixTransform.WorldPosition); line) see what's the address of Buffer.cBufferObject.WVP and tMatrixTransform.WorldPosition, it should end with 0. If it ends with anything else (usually 8) then it's not aligned properly.

Would be nice if you could grab screenshot as proof, maybe there's something else as well.

 

 

 

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);
	}
	else
	{
		MessageBox(NULL,"The Entity Object has no Transform Component you sure this is correct?","Error",MB_OK);	

	}

}

 

This is how I originally had it, Or am suppose to convert it when I pass it into the function and not into temporary variables?

 

and am not sure how am suppose to check the buffer memory location.

so I just took a screenshot >.<

am guessing its nots aligned as there are alot of things that ends with 8 XD

http://imgur.com/eucRH

and this second picture is how it looks like when it does work (by undeclare the string)

http://imgur.com/fyfYs

 

am not sure what option I pressesd but I found a new thing that stop my program to work >.<

http://imgur.com/O4Art

FML

 

Share this post


Link to post
Share on other sites
Zaoshi Kaba    8434
and am not sure how am suppose to check the buffer memory location.
so I just took a screenshot >.<
am guessing its nots aligned as there are alot of things that ends with 8 XD
http://imgur.com/eucRH
and this second picture is how it looks like when it does work (by undeclare the string)
http://imgur.com/fyfYs
You are right.
As you can see in first screenshot address of cBufferObject.WVP.r is 0x00c45998 which means it's not aligned.
While in second screenshot it's 0x01de5950 so it is aligned and doesn't crash.

Now you just need to figure which new call to fix, or use special functions to load/unload unaligned data into local variables. Edited by Zaoshi Kaba

Share this post


Link to post
Share on other sites
yckx    1298

You're not using new, but you're using smart_ptr, so it's still dynamic memory allocation.

 

 

 

I did some googling and found a page that indicates that Microsoft's implementation of shared_ptr correctly aligns its objects. I also found a 2010 post that said that there was posts known issue with boost::make_shared() such that it did not align dynamically created objects, although explicitly constructing a boost::shared_ptr would properly align the dynamically created object.

 

 

 

So i would try calling shared_ptr() instead of make_shared().

Share this post


Link to post
Share on other sites
Conny14156    279

and am not sure how am suppose to check the buffer memory location.
so I just took a screenshot >.<
am guessing its nots aligned as there are alot of things that ends with 8 XD
http://imgur.com/eucRH
and this second picture is how it looks like when it does work (by undeclare the string)
http://imgur.com/fyfYs
You are right.
As you can see in first screenshot address of cBufferObject.WVP.r is 0x00c45998 which means it's not aligned.
While in second screenshot it's 0x01de5950 so it is aligned and doesn't crash.

Now you just need to figure which new call to fix, or use special functions to load/unload unaligned data into local variables.

 

Now for the most retard question of the year,

how can commeting/uncommeting a std::string change my buffer into a 16 bit or not? while those two doesnt even have anything to do with each other for now

You're not using new, but you're using smart_ptr, so it's still dynamic memory allocation.

 

 

 

I did some googling and found a page that indicates that Microsoft's implementation of shared_ptr correctly aligns its objects. I also found a 2010 post that said that there was posts known issue with boost::make_shared() such that it did not align dynamically created objects, although explicitly constructing a boost::shared_ptr would properly align the dynamically created object.

 

 

 

So i would try calling shared_ptr() instead of make_shared().

If I try to call shared_ptr it doesn't want to properly work, Its doesnt seem it want to return the component correctly so when I try to add it its complain its empty sad.png

 

 

 

 

 

Edit:
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.

Share this post


Link to post
Share on other sites
Zaoshi Kaba    8434

[quote name='Conny14156' timestamp='1357481151' post='5018188']
how can commeting/uncommeting a std::string change my buffer into a 16 bit or not? while those two doesnt even have anything to do with each other for now
[/quote]

Most likely just a coincidence, unless Windows makes difference based on requested memory size and allocates it at different place.

Share this post


Link to post
Share on other sites
yckx    1298

They're both members of the same class, and class members are laid out in the order in which they're declared in the class definition. So commenting out the std::string changed where the XMMATRIX was being placed in relation to the beginning of the object.

 

Edit: And the issue has been avoided rather than corrected, so i don't believe the solved tag is warranted, and may mislead others.

Edited by yckx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this