IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Zen on December 22, 2006, 03:20:52 PM

Title: Unicode Heap Problems
Post by: Zen on December 22, 2006, 03:20:52 PM
Why is this code causing my program to crash at runtime?

FreeHeap(m_string);

m_string = AllocHeap(len(str) + 1);

*(wstring)m_string = str;


Note: I have m_string declared as heap.

Lewis
Title: Re: Unicode Heap Problems
Post by: Zen on December 22, 2006, 03:30:06 PM
Hmmmm Ive just debuged it and if i put a break point just before that method. This appears in the debug context...

Starting debug session...
Loading DLL: ntdll.dll
Loading DLL: C:\WINDOWS\system32\kernel32.dll
Loading DLL: C:\WINDOWS\system32\USER32.DLL
Loading DLL: C:\WINDOWS\system32\GDI32.dll
Loading DLL: C:\WINDOWS\system32\IMM32.DLL
Loading DLL: C:\WINDOWS\system32\ADVAPI32.dll
Loading DLL: C:\WINDOWS\system32\RPCRT4.dll
Loading DLL: C:\WINDOWS\system32\LPK.DLL
Loading DLL: C:\WINDOWS\system32\USP10.dll
Loading DLL: C:\WINDOWS\system32\msvcrt.dll
User breakpoint encountered: Address 0x00404087
HEAP[CString.exe]:
Invalid Address specified to RtlFreeHeap( 00860000, 0012FFB8 )
User breakpoint encountered: Address 0x7C901230


It was the invalid address specified for RtlFreeHeap that caught my eye. Does this mean anything?

Lewis
Title: Re: Unicode Heap Problems
Post by: Mike Stefanik on December 22, 2006, 03:35:19 PM
If you allocate memory for a Unicode string, you need to allocate at least 2 * (length + 1) bytes. Remember, each character is 2 bytes (at least; with UTF-32, each character is 4 bytes).
Title: Re: Unicode Heap Problems
Post by: Ionic Wind Support Team on December 22, 2006, 05:22:44 PM
Yep.  Aurora uses UTF-16 so the *2 is important.