Jump to content
  • Advertisement
Sign in to follow this  
ankhd

Trying to load objects one at a time

This topic is 1491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all.

I'm trying to load my data by putting the different type data into base class data storage classes

//the app loads up and the menu seems to work but sometimes pats of the menu don't render and 1 menu crashes the app on a
call to d3dxmesh->Intersect(&rayOrigin, &rayDir, &nHitCount,       

  &nFace, &fBary1, &fBary2, &fDist, NULL);

 

the thing is the mesh is valid in the debug its pointers are all valid its allocated but Intersect causes a app crash with this
First-chance exception at 0x66e6b1c9 in Towers.exe: 0xC0000005: Access violation reading location 0x490c4ff8.

no errors on loading .

I know its this class because when its removed and loaded all at start up it works
is there a major problem down in this code.

How should I load my data so its not holding up the app at startup takes 2 minutes to load
How you create meshes in another thread is it only devices that cant be created on another thread or is it resources like textures

and meshes as well
So I have this.


//-----------------------------------------------------------------------------------
//this is the base data type for the load stream data
//all objects and things we want to load need to have a class derived from this class
//-----------------------------------------------------------------------------------
class StreamLoaderBaseData
{
public:
	StreamLoaderBaseData(void){}

	virtual ~StreamLoaderBaseData(void){}

	//-----------------------------------------------------------------------------------
	//this is the member that gets called when we process the loader list
	//returns false on errors check error string
	//-----------------------------------------------------------------------------------
	virtual bool LoadStreamData(std::string &info)
	{
		ErrorStr = "Base Class LoadStreamData Member Called Empty";
		info = ErrorStr;
		return false;
	}




	//------------------------------------------------------------
	//public data
	//------------------------------------------------------------
	std::string ErrorStr;//any messages we have from loading
};//end class StreamLoaderBaseData
/////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////



//this class managers all the data to be laoded one or more blocks at a time.

//-----------------------------------------------------------------------------------------
//this will hold a list of base classes that will load there data and put it where
//its class defined it to go
//we can process anynumber per loop
//it loads data for us
//when the list is empty we are loaded
//------------------------------------------------------------------------------------------
class cStreamDataLoader
{
public:
	cStreamDataLoader(void)
	{
		NumberToLoadAtATime = 1;//howmany we want to load between breaks
		CurrentItem  = 0;//w
	}

	~cStreamDataLoader(void)
	{
		//we need to free all data
		StreamDataLoaderFreeALL();

	}


	void StreamDataLoaderFreeALL(void)
	{
		for(DWORD ctr = 0; ctr < DataToBeLoaded.size(); ctr++)
		{
			SAFE_DELETE(DataToBeLoaded[ctr])
		}

	}


	//-------------------------------------------------------------------------------------
	//this will load all our members
	//-------------------------------------------------------------------------------------
	bool StreamDataLoaderProcess(std::string &info)
	{
		bool val = false;

		if(CurrentItem >= DataToBeLoaded.size())
			return true;//we are done or its empty

		DWORD end = CurrentItem + NumberToLoadAtATime;
		if(end > DataToBeLoaded.size())
			end = DataToBeLoaded.size();

		//process the items
		for(DWORD ctr = CurrentItem; ctr < end; ctr++)
		{
			val = DataToBeLoaded[ctr]->LoadStreamData(info);
			if(val == false)
				return false;//error

			CurrentItem++;
		}

	}//end StreamDataLoaderProcess
	///////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////





	//---------------------------------------------------------------------------
	//returns true if we have processed the whole list of load objects
	//----------------------------------------------------------------------------
	bool LoadCompleated(void)
	{
		if(CurrentItem >= DataToBeLoaded.size())
			return true;//we are done or its empty

		return false;
	}






//holds all the data we want to load
	std::vector<StreamLoaderBaseData *> DataToBeLoaded;
	int NumberToLoadAtATime;//howmany we want to load between breaks
	int CurrentItem;//what Item we are processing


};//end class cStreamDataLoader
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////


/this is my menu data loading data it needs to load a menu

//------------------------------------------------------------------------------------
//this class is how we load our menus now
//we create a class that holds data we want to add
//and the source for the loaded data and we load them one at a time
//we need to keep our menu order because the menues are define in order
//------------------------------------------------------------------------------------
class cLoadStreamDataMenuSystem :public StreamLoaderBaseData
{
public:

	cLoadStreamDataMenuSystem(void){}

	virtual ~cLoadStreamDataMenuSystem(void){}


	//-----------------------------------------------------------------------------------
	//this is the member that gets called when we process the loader list
	//returns false on errors check error string
	//-----------------------------------------------------------------------------------
	virtual bool LoadStreamData(std::string &info);






	//-----------------------------------------------------------------------------
	//this is the data we need to set to lad a menu all data here must be valid
	//-----------------------------------------------------------------------------
	HWND Hwnd; 
	float Zoom; 
	D3DXMATRIX *OrthograpicProjection;
	D3D10_VIEWPORT ViewPort;
	Camera2 *Camera;
	int MenuType;//deffine in menu 

	//where we want to place the loaded data
	std::vector<cBaseMenu *> *MenuSystem;//its a pointer the the list

	//we need to allocate this when we add this item to the loadstream list because we need them to be of there
	//menu type
	cBaseMenu *Menu;//we allocate this based on its type where using our menu defined names
};//end class cLoadStreamDataMenuSystem
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//in create I add all the defined data like so

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//we now add data to the load manager to do stream loading
cLoadStreamDataMenuSystem *ltdms = new cLoadStreamDataMenuSystem;//this holds all data neaded for each menu
	if(ltdms == NULL)
	{
		msg = "No Memory cLoadStreamDataMenuSystem";
		SetErrorMessage(msg, label);
		Menu_ErrorBoxPtr->SetVisible(true);
		return false;//error

	}

ltdms->Hwnd		= Hwnd; 
ltdms->Zoom		= Zoom; 
ltdms->OrthograpicProjection	= OrthograpicProjection;
ltdms->ViewPort		= ViewPort;
ltdms->Camera		= Camera;
ltdms->MenuType		= MENU_SYSTEM_GAMELOBBY;//deffine in menu 

	//where we want to place the loaded data
	ltdms->MenuSystem = &MenuSystem;//its a pointer the the list


******Maybe here will push_back cast the menu to its base pointer
	//add the data to the loader 
	StreamDataLoader.DataToBeLoaded.push_back(ltdms);




//loads the menues data

//-----------------------------------------------------------------------------------
//this is the member that gets called when we process the loader list
//returns false on errors check error string
//-----------------------------------------------------------------------------------
bool cLoadStreamDataMenuSystem::LoadStreamData(std::string &info)
{

	ErrorStr = "";
	//base on the datas type we need to allocate the correct class type
	switch(MenuType)
	{
		case MENU_SYSTEM_GAMELOBBY:
		{
			Menu = new cMenuGameLobby;
			ErrorStr = "cMenuGameLobby ";
		}break;
		case MENU_SYSTEM_GAMESELECTION:
		{
			Menu = new cMenuGameSelection;
			ErrorStr = "cMenuGameSelection ";
		}break;
		case MENU_SYSTEM_GAMEJOIN:
		{
			Menu = new cMenuGameJoin;
			ErrorStr = "cMenuGameJoin ";
		}break;
		case MENU_SYSTEM_GAMELOGIN:
		{
			Menu = new cMenuGameLogIn;
			ErrorStr = "cMenuGameLogIn ";
		}break;
		case MENU_SYSTEM_GAMECREAREACCOUNT:
		{
			Menu = new cMenuGameCreateAccount;
			ErrorStr = "cMenuGameCreateAccount ";
		}break;
		case MENU_SYSTEM_GAMEEDITACCOUNT:
		{
			Menu = new cMenuGameEditAccount;
			ErrorStr = "cMenuGameEditAccount ";
		}break;
		case MENU_SYSTEM_GAMEMAIN:
		{
			Menu = new cMenuGameMain;
			ErrorStr = "cMenuGameMain ";
		}break;
		case MENU_SYSTEM_GAMEINFO:
		{
			Menu = new cMenuGameInfo;
			ErrorStr = "cMenuGameInfo ";
		}break;
		case MENU_SYSTEM_PLAYEROPTIONS:
		{
			Menu = new cMenuGamePlayerOptions;
			ErrorStr = "cMenuGamePlayerOptions ";
		}break;
		case MENU_SYSTEM_MAPSETTINGS:
		{
			Menu = new cMenuGameMapSettings;
			ErrorStr = "cMenuGameMapSettings ";
		}break;
		case MENU_SYSTEM_GAMESETTINGS:
		{
			Menu = new cMenuGameSettings;
			ErrorStr = "cMenuGameSettings ";
		}break;
		case MENU_SYSTEM_GAMEABOUT:
		{
			Menu = new cMenuGameAbout;
			ErrorStr = "cMenuGameAbout ";
		}break;
		
		default:
		{
			ErrorStr = "Unknown Menu Type LoadStreamDataMenuSystem::LoadStreamData()";
			return false;
		}break;
	}//end menutype


	if(Menu == NULL)
	{
		ErrorStr += "Failed To Allocate Menu LoadStreamDataMenuSystem::LoadStreamData()";
		return false;
	}


	info = ErrorStr;


	//ok continue loading

	//load the lobby
	if(Menu->MenuLoad(Hwnd, Zoom, *OrthograpicProjection, ViewPort, *Camera) == false)
	{
		//get the error buffer
		std::string erroelog;	
		Menu->GetErrorLogString(erroelog);
		if(erroelog.size() > 0)
		{
			//display the error
			//MessageBox(Window.Hwnd,erroelog.c_str(), "WinApp::Create", MB_OK);
			//msg = erroelog.c_str();
			if(Menu_ErrorBoxPtr)
			{
				Menu_ErrorBoxPtr->SetErrorMessage(erroelog, ErrorStr);
				Menu_ErrorBoxPtr->SetVisible(true);

			}//end valid Menu_ErrorBoxPtr
		}

		return false;
	}


	//set it visible
	Menu->SetVisible(true);

	//add it now
	MenuSystem->push_back(Menu);

	
	return true;
}//end LoadStreamData
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

//this loads the menu in the main apps loop at run time so I can update the load bar
 

//-----------------------------------------------------------------------------------------
//this will do the loading of the menu so we can return load info back to the render
//returns true when its done loading all data
//-----------------------------------------------------------------------------------------
bool LoadMenuData(void)
{
	std::string info;
	


	if(StreamDataLoader.StreamDataLoaderProcess(info) == false)
	{
		//errors
		return false;
	}


	//Loadbar_MainLoadBarPtr->IncreamentLoadBar(info, true, StreamDataLoader.DataToBeLoaded.size());


	if(StreamDataLoader.LoadCompleated())
	{

		//set so we can now use the interface elements
		m_InterfacesLoaded = true;

		StreamDataLoader.StreamDataLoaderFreeALL();//we can clear our list

		return true;//where done the whole list
	}

	return false;//we are not done yet


}//end LoadMenuData
/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////


Share this post


Link to post
Share on other sites
Advertisement

The first thing that jumps at me is that your class cLoadStreamDataMenuSystem is not aligned. And the address it's complaining about is also not aligned. Try ensuring your cLoadStreamDataMenuSystem begins on an aligned memory address.

 

[edit] Reading back, your class holds a pointer to a matrix rather than an instance. So that's probably not the direct issue, but make sure the OrthographicProjection matrix is aligned. It does seem to be complaining about alignment to me (due to the address ending in F8, which is not 16byte aligned. The typical alignment for vectors and matrices)..

 

n!

Edited by nfactorial

Share this post


Link to post
Share on other sites

Oh That was one hell of a Error.

 

It was me again.

 

this is how it went about 4 month ago I created a function GetMeshDepth(Mesh *m);

//that was locking the vetex buffer and mapping it to a skinning vertex data structure now present time I'm using it for

my menues the thing is they only have position normal and text in there vertex data. So when I used the GetMeshDepth()

function in some of the 12 menues there where writting out of bounds.

 

I wounder why it only started to crash when I tryed loading the menues in a array.????????

 

that VB lock was doing something very strange to only now show signs of problems.

 

 

Is there a way to stop doing things like that I forgot all about the meshes vertex data types.

Share this post


Link to post
Share on other sites
Store also the vertex stride (or even the full metadata, i.e. the array of input elements) and do a check/assert when loading.

Share this post


Link to post
Share on other sites

This is a good Idea.

Store also the vertex stride (or even the full metadata, i.e. the array of input elements) and do a check/assert when loading.

I do have the stride saved to;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!