Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

BungoMan85

hmmm, could this be causing a memory leak?

This topic is 5638 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

using the sweet snippits thing from a day or so ago i messed around with this just for fun
  
case WM_KEYDOWN:	switch (wParam)
							{
								case VK_SPACE:	if (Voice!=NULL)
												{
													char *Text="Ich bin eine Nilpferd";
													WCHAR *TextBuffer=new WCHAR;
													MultiByteToWideChar(CP_ACP,MB_COMPOSITE,Text,strlen(Text),TextBuffer,strlen(Text)*2);
													Voice->Speak(TextBuffer,SPF_DEFAULT,NULL);
												}
												break;
  
see im a lil worried about WCHAR *TextBuffer=new WCHAR; cause i mean it IS allocating a new WCHAR =/ but theres one problem if i try and delete it i get a runtime error =( and im not sure why if i do delete []TextBuffer; (or just delete TextBuffer; for that matter) i get the following error
  
Microsoft Visual C++ Debug Library

Debug Error!

Program: C:\Program Files\Microsoft Visual Studio\My Projects\Voice\Debug\Voice.exe

DAMAGE: after Normal block (#40) at 0x00860090.

(Press Retry to debug the application)
  
i KNOW it has to be caused by my deleting the TextBuffer =/ but if i dont delete it... then wont it cause a memory leak? or have i been lied to all along? lol Bungo!

Share this post


Link to post
Share on other sites
Advertisement
The bug is here (I think):
MultiByteToWideChar(CP_ACP,MB_COMPOSITE,Text,strlen(Text),TextBuffer,strlen(Text)*2);

int MultiByteToWideChar(
UINT CodePage, // OK
DWORD dwFlags, // OK
LPCSTR lpMultiByteStr, // OK
int cchMultiByte, // OK but if this is NULL terminated string You can put -1
LPWSTR lpWideCharStr, // OK
int cchWideChar // BUG !!!!!!
);

You dont have allocated strlen(Text)*2 buffer for output, but only one WCHAR:
WCHAR *TextBuffer=new WCHAR;

Incres buffer size and shold be OK. i think.

Share this post


Link to post
Share on other sites
DOH =P

so i should do WCHAR *TexBuffer=new WCHAR[strlen(Text)*2]; ? ill try that, thanks =P (i dunno why that never occured to me, ive had to do that sooo many times before)

Bungo!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!