Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Bug #666: Invalid de allocation/deletion of object
Product:
TV3D SDK 6.5
Language:
C#
Current State:
Closed
Resolution:
Fixed
Created On:
February 7th, 2007
Last Modified:
February 22nd, 2007
Reported By:
torbjoen
Hi,

Using the latest MTV3D65.dll (17 Dec 06), I ran an error check using DevPartner.

There were two errors inside MTV3D65.dll reported, as presented below.

If you have not already done is, you should consider using the 15-day evaluation license of DevPartner to detect error, memory leaks etc. Check it out at: (Link)

Cheers,
Torbjørn

----------------------------------------
#1

Argument 1 in DeleteObject (the object HGDIOBJ__ ho = 0x75051944) is still selected in to hDC 0xA901196A.

Current Call Stack - Thread 0 0x1208
MTV3D65.dll!0x000ac0e0


Bitmap Selection Call Stack - Thread 0 0x1208
MTV3D65.dll!0x000abe81


-------------------

Explanation:

DevPartner Error Detection

Attempting to Delete a Resource Selected in a Device Context Description
It is improper to call DeleteObject on a Gdi resource which is still selected in a Device Context.

Sample Code
void CMainFrame::OnCreateBrush()
{
CClientDC dc(this);
CBrush brush;
brush.CreateSolidBrush(RGB(0xff,0x00,0xff));
CBrush* pOldBrush = dc.SelectObject(&brush);
}


Repair
To repair the sample code, add the following line at the end of the example:
dc.SelectObject(pOldBrush);

The repaired code looks like this:

void CMainFrame::OnCreateBrush()
{
CClientDC dc(this);
CBrush brush;
brush.CreateSolidBrush(RGB(0xff,0x00,0xff));
CBrush* pOldBrush = dc.SelectObject(&brush);
dc.SelectObject(pOldBrush);
}


Note: The destructor for any CGdiObject derived class (such as CFont, CBitmap) will automatically call ::DeleteObject on the associated HGDIOBJ. It is important that you remove it from the DeviceContext before the destructor is called for you.

------------------------------------------------------------------------------------------

#2

Argument 1 in DeleteDC (HDC__ hdc = 0xA901196A) still contains non default/stock objects. Font (0x3B0A195E).

Current Call Stack - Thread 0 0x1208
MTV3D65.dll!0x000ac0e7


Font Selection Call Stack - Thread 0 0x1208
C:\WINDOWS\system32\usp10.dll!0x0001e12d
C:\WINDOWS\system32\usp10.dll!0x00014879
C:\WINDOWS\system32\lpk.dll!0x000031bc
C:\WINDOWS\system32\lpk.dll!0x00003227
C:\WINDOWS\system32\gdi32.dll!0x000216ed
C:\WINDOWS\system32\gdi32.dll!0x0000d471
MTV3D65.dll!0x000abf66

-------------------

Explanation:

DevPartner Error Detection

DeleteDC Contains Selected Objects Description
It is improper to DeleteDC a DeviceContext that still contains non-default objects.

Sample Code
void CMainFrame::OnCreateBrush() {
CBrush brush;
Brush.CreateSolidBrush(RGB(0xff,0x00,0xff));
if (true) {
CClientDC dc(this);
CBrush* pOldBrush = dc.SelectObject(&brush);
}
}


Repair
To repair the sample above, add this line before the closing brackets:

dc.SelectObject(pOldBrush);

The repaired code looks like this:

void CMainFrame::OnCreateBrush() {
CBrush brush;
Brush.CreateSolidBrush(RGB(0xff,0x00,0xff));
if (true) {
CClientDC dc(this);
CBrush* pOldBrush = dc.SelectObject(&brush);
dc.SelectObject(pOldBrush);
}
}


Note: The destructor of CDC will DeleteDC the DeviceContext at the end of scope for the if statement.

---------------------------------------------------------------------------------------------------------

Comments:

Posted by SylvainTV on February 22nd, 2007 at 10:17 PM
I think I fixed that :p
That's really a small thing though. DevPartner is really nitpicking on that :)
Reordered the calls and set default objects back when I was done.
Let me know if it still happens.