• Create Account

### #ActualConny14156

Posted 06 January 2013 - 06:44 AM

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]->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

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

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

### #1Conny14156

Posted 06 January 2013 - 05:57 AM

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]->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

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

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

PARTNERS