高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】application wont run with my tooltips class
application won't run with my tooltips class
application won't run with my tooltips class
hello
when i run my application in debug mode i get this message box error:
______________ ______________
program: ...grams\seq2dwg dwg direct 251\debug\seq2dwg.exe
file: c:\dwgdirect251\include\debugstuff.h
line: 159
expression: ((char*)dest > (char*)src && (char*)dest >= ((char*)src + size)) || ((char*)dest < (char*)src && ((char*)dest + size) <= (char*)src) ||
dest == src
for information on how your program can cause an assertion
failure, see the visual c++ documentation on asserts
(press retry to debug the application - jit must be enabled)
______________ ______________
that relates to this part of your dwgdirect header:
#if !defined(dd_client_build) && defined(_msc_ver) && defined(_debug) && (_msc_ver < 1400)
#pragma function(memcpy)
inline void * memcpy(void * dest, const void * src, size_t size)
{ // memory blocks must not overlap
oda_assert(((char*)dest > (char*)src && (char*)dest >= ((char*)src + size)) ||
((char*)dest < (char*)src && ((char*)dest + size) <= (char*)src) ||
dest == src );
return memmove(dest, src, size);
}
#endif // _msc_ver
______________ ______________
i examined the call stack and it turns out that my own multiline tooltip class is getting asserted because of the dwgdirect debugging methodology:
void cmultilinetooltipctrl::refittext(toolinfo *psti)
{
cstring strfittedtext ;
uint ulength, umaxwidth ;
// delete any existing buffer.
if (m_pctextbuffer != null)
delete[] m_pctextbuffer ;
// allocate a new one.
if (psti != null)
{
strfittedtext = psti->lpsztext ;
umaxwidth = fittext(strfittedtext);
ulength = strfittedtext.getlength();
m_pctextbuffer = new tchar[ulength + 1];
if (m_pctextbuffer != null)
_tcscpy(m_pctextbuffer,(lpctstr)strfittedtext);
psti->lpsztext = m_pctextbuffer ;
m_mappwtoolsandwidths.setat( (void *)psti->hwnd,(word)umaxwidth);
}
}
this is the offending line:
umaxwidth = fittext(strfittedtext);
if i chnage that to somthing like umaxwidth = 100 then my application compiles and runs in debug mode with no asserts. so the problem relates to fittext:
uint cmultilinetooltipctrl::fittext(cstring &rstrtext)
{
cclientdc *pdc ;
cfont *pfnttip, *pfntold ;
crect rctmargin, rcttip ;
csize siztext ;
cstring strtextcopy, strline, strchaff ;
cstringarray arystrlines ;
uint umaxwidth, unumlines, ulineindex ;
umaxwidth = 0 ; // fallback.
getmargin(&rctmargin);
getclientrect(&rcttip);
// reduce by the given margins to get the true area.
rcttip.left += rctmargin.left ;
rcttip.top += rctmargin.top ;
rcttip.right -= rctmargin.right ;
rcttip.bottom -= rctmargin.bottom ;
pdc = new cclientdc(this);
if (pdc != null)
{
pfnttip = getfont();
pfntold = (cfont *)pdc->selectobject(pfnttip);
// first, find the longest line.
strtextcopy = rstrtext ;
umaxwidth = 0 ;
while (strtextcopy != _t("") )
{
strline = strtextcopy.spanexcluding(_t("\r\n") );
strtextcopy.delete(0, strline.getlength() );
strchaff = strtextcopy.spanincluding(_t("\r\n") );
strtextcopy.delete(0, strchaff.getlength() );
siztext = pdc->gettextextent(strline);
if (siztext.cx > (int)umaxwidth)
umaxwidth = siztext.cx ;
arystrlines.add(strline);
}
rstrtext = _t("");
unumlines = arystrlines.getsize();
// now, pad all lines to that max width.
for (ulineindex = 0 ; ulineindex < unumlines ; ulineindex++)
{
strline = arystrlines.getat(ulineindex);
siztext = pdc->gettextextent(strline);
while (siztext.cx <= (int)umaxwidth)
{
strline += _t(" ");
siztext = pdc->gettextextent(strline);
}
rstrtext += strline ;
}
sendmessage(ttm_setmaxtipwidth, 0, umaxwidth);
pdc->selectobject(pfntold);
delete pdc ;
}
return umaxwidth ;
}
sorry for putting yards of code in this message thread but i am abit out of my depth here. i can tell you that the problem relates to one of the cstring derived calls, specifically, it is failing here:
strchaff = strtextcopy.spanincluding(_t("\r\n") );
what can i do to get my code to work with dwgdirect so that it won't assert? thank you.
i added a define directive for dd_client_build to my application. problem resolved.
andrew
but note that the reason of assertion was that memcpy() was called for overlapping regions of memory which is incorrect (may not work).
memmove() should be used in such cases.
defining the symbol just hides the potential problem.
sergey slezkin
ok. but my class is using the cstring spanexcluding spanincluding (code is not to hand right now) functions which are microsoft mfc supplied. so i am not doing these memory calls myself ... so i don't really know what is wrong with the cstring class. if it were not for these mem replacements in dwgdirect, i would never know about such a problem.
andrew
|