problem with MyGUI::UString


07-09-2010 02:20:03

hi, there!

in my app, i want to transmit a chat message by the raknet.
so i use the MyGUI::UString to get the chat message,
MyGUI::UString message= _sender->getCaption()

and then transmit it use the raknet mClient->send() function.

RakNet::BitStream data;

mClient->Send(&data, HIGH_PRIORITY, RELIABLE, 0, mServerAddress, false);

in the raknet Server, i also use the MyGUI::UString to get the transmitted message,

case NetworkPackPlayerChat:
RakNet::BitStream bitStream(pack, length, false);
MyGUI::UString mmessage;

this->HandlePlayerChat(mmessage); //<-----------------this line will break

then there will be a Debug Assertion Failed, shows

Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse

i think that's caused by twice delete the MyGUI::UString mmessage, once is the MyGUI::UString destructor, and the other is memory deallocate of mmessage.

how can i solve this problem, tks.


07-09-2010 02:34:30

Use pointer to MyGUI::Unstring and let it be destroyed, something like:
case NetworkPackPlayerChat:
RakNet::BitStream bitStream(pack, length, false);
MyGUI::UString *mmessage = new MyGUI::UString();

this->HandlePlayerChat(*mmessage); //<-----------------this line will break
// no 'delete mmessage' here
This code will fix your problem, but I don't really think that double destruction is your problem.


07-09-2010 09:16:46

yes, you are right. the problem is sill.

in the output box, show this

HEAP[tut3D.exe]: Invalid Address specified to RtlValidateHeap( 017D0000, 074AC8B8 )

in the callstack, the app brakdowm for below,
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
_ASSERTE(_CrtIsValidHeapPointer(pUserData)); //<-----------here

it's strange taht , if there is less than 8 characters(no matter english or unicode wide character) in the chat edit caption, it will transmit properly.
but if there are more than 8 characters, it will show the assert and break down.

is there some limit with MyGUI::UString?