Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: CTVScreen2DText memory leak?  (Read 870 times)
Baiame
Customers
Community Member
*****
Posts: 45


« on: July 04, 2009, 07:50:07 PM »

I studied this memory leak for hours, possibly because I was looking in the wrong places. On my machine this example:
Code:
CTVScreen2DText* text = new CTVScreen2DText();
int font = text->NormalFont_Create("blahblah", "Arial", 10, false, false, false);
text->Action_BeginText(true);
text->NormalFont_DrawText("Jah!", 0, 0, RGBA(1, 1, 1, 1), font);
text->Action_EndText();

gives me this non-critical runtime error on the NormalFont_DrawText line:
First-chance exception at 0x7c812a5b in lom.exe: Microsoft C++ exception: long at memory location 0x0012faa8..

This happens only on every call to a DrawText function, whether TextureFont or NormalFont, and regardless of whether it's wrapped in Action_ functions. Note that everything in Screen2DText works fine so far as the results are concerned. _CrtDumpMemoryLeaks() spits out:

Detected memory leaks!
Dumping objects ->
{149} normal block at 0x00F17878, 52 bytes long.
 Data: <xx  xx  xx      > 78 78 F1 00 78 78 F1 00 78 78 F1 00 CD CD CD CD
c:\code\leadersofmen\lom\arrays.h(52) : {148} normal block at 0x00F17818, 36 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{147} normal block at 0x00F17730, 168 bytes long.
 Data: <<zB 8zB 4zB 0zB > 3C 7A 42 00 38 7A 42 00 34 7A 42 00 30 7A 42 00
{137} normal block at 0x00F176F0, 4 bytes long.
 Data: <    > 00 00 00 00
{136} normal block at 0x00F176B0, 4 bytes long.
 Data: <    > CD CD CD CD
{135} normal block at 0x00F17670, 4 bytes long.
 Data: <    > CD CD CD CD
{134} normal block at 0x00F17630, 4 bytes long.
 Data: <    > CD CD CD CD
{133} normal block at 0x00F175F0, 4 bytes long.
 Data: <    > CD CD CD CD
{132} normal block at 0x00F175B0, 4 bytes long.
 Data: <    > CD CD CD CD
{131} normal block at 0x00F17570, 4 bytes long.
 Data: <    > CD CD CD CD
{129} normal block at 0x00F172E0, 4 bytes long.
 Data: <    > CD CD CD CD
{128} normal block at 0x00F172A0, 4 bytes long.
 Data: <    > CD CD CD CD
{126} normal block at 0x00F17010, 4 bytes long.
 Data: <    > CD CD CD CD
{125} normal block at 0x00F16550, 2688 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.


And here's the disassembly, though I doubt it's relevant:
Code:
00412FD1  mov         esi,esp
00412FD3  mov         eax,dword ptr [font]
00412FD6  push        eax 
00412FD7  mov         edi,esp
00412FD9  push        ecx 
00412FDA  fld1             
00412FDC  fstp        dword ptr [esp]
00412FDF  push        ecx 
00412FE0  fld1             
00412FE2  fstp        dword ptr [esp]
00412FE5  push        ecx 
00412FE6  fld1             
00412FE8  fstp        dword ptr [esp]
00412FEB  push        ecx 
00412FEC  fld1             
00412FEE  fstp        dword ptr [esp]
00412FF1  call        dword ptr [__imp_RGBA (42E6A0h)]
00412FF7  add         esp,10h
00412FFA  cmp         edi,esp
00412FFC  call        @ILT+1620(__RTC_CheckEsp) (411659h)
00413001  push        eax 
00413002  push        ecx 
00413003  fldz             
00413005  fstp        dword ptr [esp]
00413008  push        ecx 
00413009  fldz             
0041300B  fstp        dword ptr [esp]
0041300E  push        offset string "Jahhhhhhh!" (427B70h)
00413013  mov         ecx,dword ptr [text (42CEF4h)]
00413019  call        dword ptr [__imp_CTVScreen2DText::NormalFont_DrawText (42E750h)]
0041301F  cmp         esi,esp
00413021  call        @ILT+1620(__RTC_CheckEsp) (411659h)

Hope this helps. I'm still a relative noob programmer, so sorry if it's due to some bizarre mangling of my own.

EDIT- Actually, if I call CrtDumpMemoryLeaks after instantiating CTVEngine, I get this:
Detected memory leaks!
Dumping objects ->
{125} normal block at 0x00F16550, 4 bytes long.
 Data: <    > CD CD CD CD
Object dump complete.


without the exception report. If I call it any time before CTVEngine is instatiated, nothing is dumped. I've also removed the only other external library I was using. I spoke too soon on CTVScreen2DText working- it doesn't work at all.

EDIT3:

Okay, finally I have some answers. My original problem was too stupid to mention. However, the reason why I didn't quickly discover the source of the problem were minor, red-herring memory leaks that apparently exist in the TV engine. When CTVEngine() is called, a leak of 4 bytes is reported by _CrtDumpMemoryLeaks() (jviper confirmed this on IRC). This also happens whenever any DrawText function is called- nothing actually leaks every time, but the same old leaks are reported (you're given the same addresses).

I would upload an example to replicate it but I have no file hosting of my own. Just #include <crtdbg.h> in the file where CTVEngine() is called, put _CrtDumpMemoryLeaks(); just after the call, place a breakpoint on it, debug and step over and it should happen. Obviously put the _CrtDumpMemoryLeaks() call just before CTVEngine() to establish that it's not preexisting.
« Last Edit: July 05, 2009, 04:09:23 PM by Baiame » Logged
SylvainTV
Administrator
Community Member
*****
Posts: 4946


WWW
« Reply #1 on: August 12, 2009, 07:01:20 AM »

I'm a little lost on what's happening here.
Is all ok now or is there still one TV memory leak somewhere?
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
jviper
Community Member
*
Posts: 2130

Discipline in training


« Reply #2 on: August 12, 2009, 10:32:15 AM »

I think I remember talking to someone on IRC about this issue (don't know if it was this exact issue or not). It turns out leak was not critical and that it was actually due to lag in Garbage Collecter. We determined this because the amount of memory leak was small, and the memory comsumption recovered in the middle of the running application and beyond.

But I could be wrong as this may not have been the issue I worked with.
Logged

JAbstract.....Don't just imagine, make it happen!
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks