Skip to main content
GameDev.net gamedev.net
🔒 Locked

[strings] invalid null pointer

Started by Viperrr Sep 7, 2008 at 7:55 AM 1 replies 3.4k views
Original Post
Viperrr
Viperrr
This is a piece of code that extracts D3D materials. Something is wrong with the string conversions. "tempMaterials.pTextureFilename" is of type LPSTR So I'm trying to go from LPSTR to wstring to LPCTSTR

std::wstring StringToWString(const std::string& s)
{
	std::wstring temp(s.length(),L' ');
	std::copy(s.begin(), s.end(), temp.begin());
	return temp;
}


//...
std::wstring strFileName;
for(DWORD i = 0; i < cMesh->numMat; i++)
{
	strFileName = StringToWString(tempMaterials.pTextureFilename);
	if(FAILED(D3DXCreateTextureFromFile(d3ddev, strFileName.c_str(), &cMesh->ppTexture)))
		*(&cMesh->ppTexture) = NULL;
//...

This compiles, but I get an error when I run it: "Invalid null pointer" What's going on?
visitor
visitor
Perhaps you are passing a NULL pointer to a string constructor which is not allowed. Are all tempMaterials.pTextureFilename's non-NULL?
supamike
supamike
put a breakpoint on

strFileName = StringToWString(tempMaterials.pTextureFilename);

and see what strFileName is after you call StringToWString.

also, how come your converting it to a wstring anyway? does the filename have non-latin characters in it? If so you'll lose them anyway when you convert to a cstring (because it only holds 8-bit chars - unless your using VS) and may cause the filename to be incorrect when you call D3DXCreateTextureFromFile.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.