non static or const array syntax - c++

what's wrong with this syntax? sorry for the newbie question.
source:
Level::Level()
{
NintyDegreeDirections[4] =
{
1.0f, 1.4f, 2.4f, 0.1f
}
...rest of class
header:
//all necessary includes
class Level
{
private:
float NintyDegreeDirections[4];
...rest of header
how do I have an array as a instance member? I'm converting from C#

In the current version of C++ (C++11), you can initialize the member array like this:
Level::Level()
: NintyDegreeDirections( { 1.0f, 1.4f, 2.4f, 0.1f } )
{
}
C++11 isn't universally supported and if you don't have support for this in your compiler you will have to assign to each member in turn.
E.g.:
NintyDegreeDirections[0] = 1.0f;
NintyDegreeDirections[1] = 1.4f;
//...

Did you try:
NintyDegreeDirections[0] = 1.0f;
NintyDegreeDirections[1] = 1.4f;
/* ... */

Related

How to initialize nested struct in C++?

Let's say I have following declaration in the C++:
struct Configuration {
struct ParametersSetA {
float param_A_01;
float param_A_02;
float param_A_03;
} parameters_set_A;
struct ParametersSetB {
float param_B_01;
float param_B_02;
} parameters_set_B;
};
Then somewhere in the code I have following definition:
Configuration config = {
.parameters_set_A = {
.param_A_01 = 1.0f,
.param_A_02 = 2.0f,
.param_A_03 = param_A_01 + param_A_02;
},
.parameters_set_B = {
.param_B_01 = 0.50f,
.param_B_02 = 0.75f
}
};
My question is whether the initialization (especially as far as the param_A_03 item in the nested struct ParametersSetA)
I have used above is correct in the C++?
The problem is that we can't use any of the unqualified names param_A_01 or param_A_02 or an expression that involves any of the two like param_A_01 + param_A_02 as initializer forparam_A_03.
Additionally, you have incorrectly put a semicolon ; after param_A_01 + param_A_02 instead of comma , . I've corrected both of these in the below shown modified program:
Method 1
//create constexpr variables
constexpr float A1 = 1.0f;
constexpr float A2 = 2.0f;
Configuration config = {
.parameters_set_A = {
.param_A_01 = A1,
.param_A_02 = A2,
//--------------vv---vv---->use those constexpr variable(also semicolon is removed from here)
.param_A_03 = A1 + A2
},
.parameters_set_B = {
.param_B_01 = 0.50f,
.param_B_02 = 0.75f
}
};
Working demo
Method 2
Other option is to use qualified names like config.parameters_set_A.param_A_01 and config.parameters_set_A.param_A_02 as shown below:
Configuration config = {
.parameters_set_A = {
.param_A_01 = 1.0f,
.param_A_02 = 2.0f,
//--------------vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv--->qualified name used here
.param_A_03 = config.parameters_set_A.param_A_01 + config.parameters_set_A.param_A_02
},
.parameters_set_B = {
.param_B_01 = 0.50f,
.param_B_02 = 0.75f
}
};
Working demo

c++: Proper way to initialize static fields of member struct

I got this:
// mouse.h
class Mouse {
private:
struct Pos {
static GLfloat x;
static GLfloat y;
};
static Pos last;
}
and this:
// mouse.cpp
// 1)
Mouse::Pos Mouse::last = {};
// 2)
Mouse::Pos Mouse::last = { 0.0, 0.0 };
// 3)
Mouse::last.x = 0.0f;
Mouse::last.y = 0.0f;
1), 2) and 3) are the attempts I've made at initializing that thing. I understand that the header should declare that last is static, and that the source should initialize it, but something has been wrong with all my attempts. Could someone please tell me the correct way to do such a thing? Am I missing some very important point? Is this nonsense? It is important that the fields are static. Thanks.
You don't need to declare Pos content as static.
// mouse.h
class Mouse {
private:
struct Pos {
GLfloat x;
GLfloat y;
};
static Pos last;
}
Mouse::Pos Mouse::last = { 0.0, 0.0 };
This should work too
It is important that the fields are static.
Then last will not have any state. It will simply refer to the static x and y values inside Mouse::Pos.
#include "mouse.h"
GLfloat Mouse::Pos::x = 10;
GLfloat Mouse::Pos::y = 10;
Mouse::Pos Mouse::last{};
wandbox example
The following asserts pass:
assert(Mouse::last.x == 10);
assert(Mouse::last.y == 10);

c++ iterating through vector returns objects that aren't even in it

I'm putting together a pinball table, and here I have a PinballTable class. I want to hold all of the game objects (pinball, bumpers, flippers, etc) in a vector, which I call _gameObjs.
When I iterate through the vector, its returning the last GameObj declared in the constructor, whether that GameObj is in the vector or not. If I add multiple GameObjs to the vector, it will return that last declared GameObj that many times. I'm transitioning from C# and collections seem to be getting the best of me, I'm totally stumped here though
Here, I'm added three objects: two bumpers and one pinball. In the update function, I'm trying to get it to output output the x size of each object just so I know it's iterating correctly. Here, for example, I haven't even added the pinball to the vector, but it's outputting the pinball's x size twice per update call.
#include "PinballTable.h"
GameObj* _pinball;
int TABLE_WIDTH;
int TABLE_HEIGHT;
float _tableTiltedAngle = 6.5f;
float _radiansPerDegree = PI / 180;
float _gravityForce = cos( _tableTiltedAngle * _radiansPerDegree ) * GRAVITY;
vector<GameObj> _gameObjs;
PinballTable::PinballTable( const int width, const int height )
{
TABLE_WIDTH = width;
TABLE_HEIGHT = height;
GameObj bumper1(
GameObj::shapeCircle,
GameObj::typeStatic,
color4f( 1.0f, 1.0f, 0.0f, 1.0f),
point2f( 300.0f, 600.0f ),
vec2f( 40.0f, 0.0f )
);
_gameObjs.push_back( bumper1 );
GameObj bumper2(
GameObj::shapeCircle,
GameObj::typeStatic,
color4f( 1.0f, 1.0f, 0.0f, 1.0f),
point2f( 50.0f, 200.0f ),
vec2f( 50.0f, 0.0f )
);
_gameObjs.push_back( bumper2 );
GameObj pinball(
GameObj::shapeCircle,
GameObj::typeDynamic,
color4f( 1.0f, 1.0f, 0.0f, 1.0f),
point2f( 100.0f, 100.0f),
vec2f( 20.0f, 20.0f)
);
_pinball = &pinball;
}
PinballTable::~PinballTable(void)
{
}
// ------------------------------ Update Functions ------------------------------
void PinballTable::update( GameTime& gameTimer )
{
for( vector<GameObj>::iterator i = _gameObjs.begin(); i != _gameObjs.end(); ++i )
{
cout << i->getSize()->x << endl;
}
}
thanks for the help
get size function just returns a vector2 (x, y components) from a GameObj. The output size matches up with the last declared GameObj size in the PinballTable constructor every time
vec2f* GameObj::getSize( void )
{
return &_size;
}
Solved:
One of the problems, as pointed out by a few, was that the GameObjs are created inside the constructor.
In the GameObj class I was not declaring the different members in the header file. Switching these members to the header file seemed to fix this, for what reason I do not know.
You created 3 GameObj inside the constructor which are going to be destructed after the constructor returns and when you add them to the vector, they are garbage.
Is your GameObj an interface or abstract class? If so, you should not put it directly into a vector, but a pointer to it. Think of a vector as a byte-array containing of serialized copies of what you put into it (since you are coming from C# this should help). C++ does not have a uniform object representation, so it is crucial to keep in mind what space your objects require.
Is this you want,
for( vector<GameObj>::iterator i = _gameObjs.begin(); i != _gameObjs.end(); ++i )
{
cout << (*i).getSize()->x << endl;
}
You need to get the object stored in the vector by the dereference(*) operator.
If at all possible, I'd use a range-based for loop:
for (auto const &g : _gameObjs)
cout << g.getSize()->x << "\n";
This was added in C++11, so you may have to give your compiler a switch to tell it to recognize/allow C++11 constructs (e.g., you normally have to with g++).
The way that you describe your problem, it sounds as if _size is a global variable, and not a member of GameObj

error C2146: syntax error : missing ';' before identifier 'ContextRecord'

i have a header file which contained all of the class' functions including code so the class didn't have a cpp file. everything worked. I added the cpp file and moved the function code over to that and now i get this error when compiling. the header that im getting the error in ((x86)\microsoft sdks\windows\v7.0a\include\winnt.h(6361)) isnt even included by the file that im changing. does anyone know what the reason for this might be? i can provide code i just don't know what would be helpful.
the cpp file:
#include "Fisherman.h"
void Fisherman::Initialise(){
memset((void*)&mListener, 0, sizeof(X3DAUDIO_LISTENER));
memset((void*)&mEmitter, 0, sizeof(X3DAUDIO_EMITTER));
memset((void*)&mDSPSettings, 0, sizeof(X3DAUDIO_DSP_SETTINGS));
XAUDIO2_VOICE_DETAILS details;
mCastSplash->GetSourceVoice()->GetVoiceDetails(&details);
mEmitter.ChannelCount = details.InputChannels;
mEmitter.CurveDistanceScaler = 1.0f;
X3DAUDIO_VECTOR emitterPos = { 0.0f, 0.0f, 0.0f};
mEmitter.Position = emitterPos;
X3DAUDIO_VECTOR emitterVel = { 0.0f, 0.0f, 0.0f };
mEmitter.Velocity = emitterVel;
mDSPSettings.SrcChannelCount = mEmitter.ChannelCount;
mDSPSettings.DstChannelCount = mXACore->GetChannelCount();
FLOAT32 * matrix = new FLOAT32[mDSPSettings.SrcChannelCount * mDSPSettings.DstChannelCount];
mDSPSettings.pMatrixCoefficients = matrix;
X3DAUDIO_VECTOR front = { 0.0f, 0.0f, 1.0f };
X3DAUDIO_VECTOR top = { 0.0f, 1.0f, 0.0f };
mListener.OrientFront = front;
mListener.OrientTop = top;
X3DAUDIO_VECTOR listenerVel = {0.0f, 0.0f, 0.0f};
mListener.Velocity = listenerVel;
X3DAUDIO_VECTOR listenerPos = { 0.0f, 0.0f, 0.0f };
mListener.Position = listenerPos;
}
void Fisherman::Rotate (int MouseDeltaX){
X3DAUDIO_VECTOR input = mListener.OrientFront;
X3DAUDIO_VECTOR result;
float theta = -(X3DAUDIO_PI/1000)*MouseDeltaX;
float cs = cos(theta);
float sn = sin(theta);
if(cs < 0.00001) cs = 0.0f;
result.x = input.x * cs - input.z * sn;
result.z = input.x * sn + input.z * cs;
result.y = 0.0f;
mListener.OrientFront = result;
}
bool Fisherman::Cast(Fish* aFish){
mCast->Play(0);
mCastOut = true;
mFish = aFish;
X3DAUDIO_VECTOR seg_v = Multiply(mListener.OrientFront, 30);
X3DAUDIO_VECTOR pt_v = {mFish->GetX(), 0.0f, mFish->GetZ()};
float proj_v_length = Dot(pt_v, mListener.OrientFront);
X3DAUDIO_VECTOR proj_v = Multiply(mListener.OrientFront, proj_v_length);
X3DAUDIO_VECTOR dist_v = Subtract(pt_v, proj_v);
if(VectorLength(dist_v) < mFish->GetRadius()){
mEmitter.Position = mFish->GetEmitter().Position;
return true;
}else{
mEmitter.Position = Multiply(mListener.OrientFront, 15);
return false;
}
}
void Fisherman::ReelIn(Fish* aFish){
mFish = aFish;
mFish->MoveCloser(mReelSpeed);
mReelingIn = true;
}
void Fisherman::ReelOut(Fish* aFish){
mFish = aFish;
mFish->MoveFurther();
mReelingIn = false;
}
void Fisherman::SetReelSpeed(float deltaTime){
float reelSpeed = 1.0f - deltaTime;
if(reelSpeed < 0.0f){
reelSpeed = 0.0f;
}
if(reelSpeed > 10){
mReelSpeedList.push_back(reelSpeed);
if(mReelSpeedList.size() > 3){
mReelSpeedList.pop_front();
}
reelSpeed = 0.0f;
std::list<float>::const_iterator iterator;
for (iterator = mReelSpeedList.begin(); iterator != mReelSpeedList.end(); ++iterator){
reelSpeed += *iterator;
}
mReelSpeed = reelSpeed/mReelSpeedList.size();
}else
mReelSpeed = reelSpeed;
mReelClickTimer = 0.1 / mReelSpeed;
}
void Fisherman::PlayReelClick(){
if(!mReelClick[0]->IsPlaying()){
mReelClick[0]->Play(0);
}else if(!mReelClick[1]->IsPlaying()){
mReelClick[1]->Play(0);
}else if(!mReelClick[2]->IsPlaying()){
mReelClick[2]->Play(0);
}else if(!mReelClick[3]->IsPlaying()){
mReelClick[3]->Play(0);
}else if(!mReelClick[4]->IsPlaying()){
mReelClick[4]->Play(0);
}else {
return;
}
}
bool Fisherman::NothingPlaying(){ // check to see if any sounds are playing
if(mCast->IsPlaying())return false;
if(mCastSplash->IsPlaying())return false;
for(int i =0; i < REEL_CLICK_OBJECTS; i++){
if(mReelClick[i]->IsPlaying()){
return false;
}
}
return true;
}
void Fisherman::SetReelingIn(bool isReelingIn){
mReelingIn = isReelingIn;
}
void Fisherman::SetCastOut(bool hasCastOut){
mCastOut = hasCastOut;
}
float Fisherman::GetReelClickTime(){
return mReelClickTimer/CLICK_TIMER_MULTIPLIER;
}
bool Fisherman::IsReelingIn(){
return mReelingIn;
}
float Fisherman::GetReelSpeed(){
return mReelSpeed;
}
X3DAUDIO_LISTENER Fisherman::GetListener(){
return mListener;
}
X3DAUDIO_EMITTER Fisherman::GetEmitter(){
return mEmitter;
}
X3DAUDIO_DSP_SETTINGS Fisherman::GetSettings(){
return mDSPSettings;
}
XASound* Fisherman::GetCastSound(){
return mCast;
}
XASound* Fisherman::GetCastSplashSound(){
return mCastSplash;
}
bool Fisherman::HasCastSplashed(){
return mCastSplashBool;
}
void Fisherman::SetCastSplashed(bool splashed){
mCastSplashBool = splashed;
}
bool Fisherman::IsCastOut(){
return mCastOut;
}
the header:
#ifndef _FISHERMAN_H_
#define _FISHERMAN_H_
#include <X3DAudio.h>
#include <math.h>
#include <list>
#include "VectorCalculations.h"
#include "Fish.h"
#include "XASound.hpp"
using AllanMilne::Audio::XASound;
const float CLICK_TIMER_MULTIPLIER = 2.5f;
const int REEL_CLICK_OBJECTS = 5;
class Fisherman{
public:
Fisherman(XACore* aXACore, XASound *cast, XASound *castSplash, std::list<XASound*> reelClickList)
: // a Fish Object pointer for the fisherman to interact with.
mFish (NULL), mXACore (aXACore),
//XASound objects with sounds for the fisherman
mCast (cast), mCastSplash (castSplash)
{
mReelSpeedList.clear();
for(int i = 0; i < REEL_CLICK_OBJECTS; i++){
mReelClick[i] = reelClickList.front();
mReelClick[i]->SetVolume(2.0f);
reelClickList.pop_front();
mReelClickList.push_back(mReelClick[i]);
}
mCastSplash->SetVolume(7.0f);
mXACore = aXACore;
mCastSplashBool = false;
mCastOut = false;
mReelingIn = false;
mCastDistance = 0.0f;
Initialise();
}
~Fisherman(){}
void Initialise();
void Rotate(int MouseDeltaX);
bool Cast(Fish* aFish);
void ReelIn(Fish* aFish);
void ReelOut(Fish* aFish);
void SetReelSpeed(float deltaTime);
void PlayReelClick();
bool NothingPlaying(); // check to see if any sounds are playing
void SetFront(X3DAUDIO_VECTOR front);
void SetReelingIn(bool isReelingIn);
void SetCastOut(bool hasCastOut);
float GetReelClickTime();
bool IsReelingIn();
float GetReelSpeed();
X3DAUDIO_LISTENER GetListener();
X3DAUDIO_EMITTER GetEmitter();
X3DAUDIO_DSP_SETTINGS GetSettings();
XASound* GetCastSound();
XASound* GetCastSplashSound();
bool HasCastSplashed();
void SetCastSplashed(bool splashed);
bool IsCastOut();
private:
XACore *mXACore;
XASound *mCast;
XASound *mCastSplash;
XASound *mReelClick[REEL_CLICK_OBJECTS];
float mCastDistance;
float mReelClickTimer;
float mReelSpeed;
std::list<float> mReelSpeedList;
std::list<XASound*> mReelClickList;
X3DAUDIO_LISTENER mListener;
X3DAUDIO_EMITTER mEmitter;
X3DAUDIO_DSP_SETTINGS mDSPSettings;
Fish *mFish;
bool mCastOut;
bool mCastSplashBool;
bool mReelingIn;
};
#endif
including windows.h at the top of the header file solved this issue.
Does the error also say PCONTEXT undefined?
Try adding #include <Windows.h> before #include <X3DAudio.h>.
In reply to comment about unresolved external symbol:
That's because you didn't define Fisherman::SetFront in the cpp file.
Whole code would be helpfull. Did you remember obvious to give namespace to names of functions etc?
class A { void foo() { } };
=>
class A { void foo(); }
void A::foo() { ... }
etc?
Fastest way would be reverting back to state when it worked, and not moving whole at once, but only one function at a time. Then when problem would occure you could give us that specific code or try to fix it yourself.
It is very possible that there is just a missed ';', somewhere before this line.
Double-check your code, remember that everything you define in a cpp file has to already be declared in your class definition.
I'd prefer to post a comment, but apparently I'm not allowed.
Anyway, as a simpler way to give us a feel of what you're trying to do, definatley post your code - it does not have to be exactly as you use, but should be a concise piece of generic code, highlighting how you are doing something. (SSCCE) If it really is a bug in how you typed it, it would be good to have your exact code, but put it on pastebin and provide a link so that this page doesn't end up with reams of code.
EDIT:
winnt.h apparently causes all sorts of problems: Weird compile error dealing with Winnt.h
it is used to provide definitions for winAPI specific headers, as far as I know. One of the solutions proposed on that thread is to get the definitions from a different windows header before including whichever header requires those definitions.

C++, why am I getting access violations after modifying newly allocated objects?

Alright, so I'm currently working on a game and ran into a memory issue after refactoring some of the code today.
It uses a component based design and I was modifying how the components were allocated and passed off to entities. Originally some components were allocated as member variables within the entities but now I want to have them allocated elsewhere and passed off to the entity via pointer.
You can see how I implemented this below with sample code from my project. I essentially iterate through all the entities and allocate the components for them. The problem is I'm hitting a access violation at the first line of "starting up" the "instanceObject" on the 6th iteration and have no idea why. Using the debugger, it doesn't look like any of the variables point to a invalid address.
Here is what I'm doing to create the entities and components.
for (unsigned int i = 0; i < 512; ++i) {
InstanceObject* _pInstanceObject = new InstanceObject;
// Initialize temporary variables
XMFLOAT3 _position, _rotation;
float _angle = (i / 512.0f) * (2.0f * XM_PI),
_scale = (float)pResourceManager->numberGenerator.GetInt(50, 5);
_position.x = 100000.0f * cos(_angle) + pResourceManager->numberGenerator.GetInt(50000, -25000);
_position.y =(float) pResourceManager->numberGenerator.GetInt(50000, -25000);
_position.z = 100000.0f * sin(_angle) + pResourceManager->numberGenerator.GetInt(50000, -25000);
_rotation.x = (XM_PI * 2) * (pResourceManager->numberGenerator.GetInt(100, 0) / 100.0f);
_rotation.y = (XM_PI * 2) * (pResourceManager->numberGenerator.GetInt(100, 0) / 100.0f);
_rotation.z = (XM_PI * 2) * (pResourceManager->numberGenerator.GetInt(100, 0) / 100.0f);
// Set component's state using the temporary variables.
_pInstanceObject->StartUp(&_position,
&_rotation,
&XMFLOAT3(_scale, _scale, _scale),
&XMFLOAT3(0.0f, 0.0f, 1.0f),
&XMFLOAT3(1.0f, 0.0f, 0.0f),
&XMFLOAT3(0.0f, 1.0f, 0.0f)
);
// Hand pointer of the component to entity.
// Entity will handle deallocating component
}
And here is the relevant code from the component.
class InstanceObject {
private:
XMVECTOR anteriorAxis,
lateralAxis,
normalAxis,
position,
rotationQuaternion,
scale;
XMMATRIX translationMatrix,
rotationMatrix,
scaleMatrix;
void SetAnteriorAxis(const XMFLOAT3 *_anteriorAxis) { anteriorAxis = XMLoadFloat3(_anteriorAxis); }
void SetLateralAxis(const XMFLOAT3 *_lateralAxis) { lateralAxis = XMLoadFloat3(_lateralAxis); }
void SetNormalAxis(const XMFLOAT3 *_normalAxis) { normalAxis = XMLoadFloat3(_normalAxis); }
public:
InstanceObject(void) { }
InstanceObject(const InstanceObject& _object) : anteriorAxis(_object.anteriorAxis), lateralAxis(_object.lateralAxis),
normalAxis(_object.normalAxis), position(_object.position), rotationQuaternion(_object.rotationQuaternion), scale(_object.scale),
translationMatrix(_object.translationMatrix), rotationMatrix(_object.rotationMatrix), scaleMatrix(_object.scaleMatrix) {}
~InstanceObject(void) { }
bool StartUp(const XMFLOAT3 *_position, const XMFLOAT3 *_rotation, const XMFLOAT3 *_scale,
const XMFLOAT3 *_lookAxis, const XMFLOAT3 *_strafeAxis, const XMFLOAT3 *_upAxis);
void SetPosition(const XMFLOAT3* _position) { position = XMLoadFloat3(_position); }
void SetRotationQuaternion(const XMFLOAT3 *_rotation) { rotationQuaternion = XMQuaternionRotationRollPitchYaw(_rotation->x, _rotation->y, _rotation->z); }
void SetScale(const XMFLOAT3 *_scale) { scale = XMLoadFloat3(_scale); }
}
bool InstanceObject::StartUp(const XMFLOAT3 *_position, const XMFLOAT3 *_rotation, const XMFLOAT3 *_scale,
const XMFLOAT3 *_lookAxis, const XMFLOAT3 *_strafeAxis, const XMFLOAT3 *_upAxis) {
SetPosition(_position);
SetRotationQuaternion(_rotation);
SetScale(_scale);
SetAnteriorAxis(_lookAxis);
SetLateralAxis(_strafeAxis);
SetNormalAxis(_upAxis);
return true;
}
Any idea of what could be causing this behavior and how should I fix it?
I believe the issue is that the XMVECTOR in your InstanceObject class need to be 16 byte aligned, and the new operator won't guarantee this for you. You can add a quick check into your code to confirm - check whether the InstanceObject pointer & 0xF is non zero in the iteration in which it crashes.
If that is the case you can write a custom allocator that guarantees the right alignment and use placement new.
It seems to be a fairly common problem with XMVECTOR when used as a member (here's an existing Connect bug report on this issue, there are a few web pages if you search).
If you just want to fix it quickly to let you get on with other things, you can add a static operator new and delete to your class declaration implemented something like the following snippet:
void* InstanceObject::operator new( size_t size )
{
// _aligned_malloc is a Microsoft specific method (include malloc.h) but its
// straightforward to implement if you want to be portable by over-allocating
// and adjusting the address
void *result = _aligned_malloc( size, 16 );
if( result )
return result;
throw std::bad_alloc();
}
void InstanceObject::operator delete( void* p )
{
if( p ) _aligned_free(p);
}
If the InstanceObject share a common lifetime you could replace the use of _aligned_malloc with your own aligned arena allocator and make the delete a no-op to improve efficiency.
You're taking the addresses of temporaries! That's not even allowed!
// Set component's state using the temporary variables.
_pInstanceObject->StartUp(&_position,
&_rotation,
&XMFLOAT3(_scale, _scale, _scale), // not valid
&XMFLOAT3(0.0f, 0.0f, 1.0f), // not valid
&XMFLOAT3(1.0f, 0.0f, 0.0f), // not valid
&XMFLOAT3(0.0f, 1.0f, 0.0f) // not valid
);
I suggest that you turn up the warning levels on your compiler settings, and enable as much standard conformance as possible. Things get much easier when your compiler tells you what you're doing wrong.
As a solution, you could try simply passing the objects by value:
_pInstanceObject->StartUp(_position,
_rotation,
XMFLOAT3(_scale, _scale, _scale),
XMFLOAT3(0.0f, 0.0f, 1.0f),
XMFLOAT3(1.0f, 0.0f, 0.0f),
XMFLOAT3(0.0f, 1.0f, 0.0f)
);
bool StartUp(XMFLOAT3 _position, XMFLOAT3 _rotation, XMFLOAT3 _scale,
XMFLOAT3 _lookAxis, XMFLOAT3 _strafeAxis, XMFLOAT3 _upAxis);
It looks like your XMFLOAT3 structures are being allocated on the stack, not on the heap. They would get cleaned up when their variables go out of scope.
Try allocating your structures on the heap instead:
XMFLOAT3* _position = new XMFLOAT3;