Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Exception Creating a Box (Read 15260 times)
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Exception Creating a Box
Aug 13th, 2007 at 12:08pm
Print Post  
I'm not 100% sure this isn't something I'm doing wrong in my own code, but I've been having a heck of a time trying to track down what is causing this.

I'm using the FlowchartX control with the GDI+ engine enabled.

Inside my applicaiton, we are using a custom ActiveX control.

I create a FlowChartX control inside that custom ActiveX control.  That control is then deleted and the FlowChartX control is deleted along with it.  (The ShutDown for GDI+ is called in that case and everything seems fine)

When I create my ActiveX control for a second time, it seems to create the FlowChartX control properly, startup GDI+, etc.  Then I hit my first "CreateBox" invocation, and I get this exception with the following stack trace:

First-chance exception at 0x4ec9004f (GdiPlus.dll) in DataAlchemy.exe: 0xC0000005: Access violation reading location 0x03fa611c.

Unhandled exception at 0x4ec9004f (GdiPlus.dll) in DataAlchemy.exe: 0xC0000005: Access violation reading location 0x03fa611c.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GdiPlus.dll!_GdipCreateFont@20()  + 0xa8 bytes
FlowChartPro.dll!04fb1426()
[Frames below may be incorrect and/or missing, no symbols loaded for FlowChartPro.dll]
FlowChartPro.dll!04fb1adf()
GdiPlus.dll!GpGraphics::GetFromHdc()  + 0x47 bytes
GdiPlus.dll!_GdipCreateFromHDC@8()  + 0x6a bytes
FlowChartPro.dll!04fb36a8()
FlowChartPro.dll!05022412()
FlowChartPro.dll!0502242f()
FlowChartPro.dll!0502245a()
FlowChartPro.dll!0502028e()
FlowChartPro.dll!04fb9524()
FlowChartPro.dll!0503544b()
FlowChartPro.dll!04f5c550()
FlowChartPro.dll!05022412()
FlowChartPro.dll!0502242f()
FlowChartPro.dll!0502245a()
FlowChartPro.dll!0502028e()
FlowChartPro.dll!04f5ce20()
FlowChartPro.dll!04f611de()
FlowChartPro.dll!0502242f()
FlowChartPro.dll!0502245a()
FlowChartPro.dll!04fa9f33()
FlowChartPro.dll!05034ba6()
oleaut32.dll!_DispCallFunc@32()  + 0xc3 bytes
oleaut32.dll!CTypeInfo2::Invoke()  + 0x20c bytes
FlowChartPro.dll!04f7cd18()

mfc80d.dll!COleDispatchDriver::InvokeHelperV(long dwDispID=0x00000016, unsigned short wFlags=0x0001, unsigned short vtRet=0x0009, void * pvRet=0x0012e42c, const unsigned char * pbParamInfo=0x04e838fc, char * argList=0x0012e424)  Line 397 + 0x38 bytes
C++

mfc80d.dll!COleControlSite::InvokeHelperV(long dwDispID=0x00000016, unsigned short wFlags=0x0001, unsigned short vtRet=0x0009, void * pvRet=0x0012e42c, const unsigned char * pbParamInfo=0x04e838fc, char * argList=0x0012e414)  Line 1093
C++

mfc80d.dll!CWnd::InvokeHelper(long dwDispID=0x00000016, unsigned short wFlags=0x0001, unsigned short vtRet=0x0009, void * pvRet=0x0012e42c, const unsigned char * pbParamInfo=0x04e838fc, ...)  Line 382
C++

CustomControl.ocx!FlowChart::CreateBox(long x=0x00000000, long y=0x00000000, long width=0x000001d4, long height=0x000001d4)  Line 370 + 0x28 bytes
C++
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception Creating a Box
Reply #1 - Aug 13th, 2007 at 12:35pm
Print Post  
That looks like a known problem. Please take a look at this topic:

http://mindfusion.org/cgi/HelpDesk/index.php?pid=knowledgebase&cmd=viewent&id=6

Stoyan
  
Back to top
 
IP Logged
 
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Re: Exception Creating a Box
Reply #2 - Aug 13th, 2007 at 3:13pm
Print Post  
Setting the default font to Arial doesn't seem to fix this issue.

Same exception and stack trace resulted when I hit the CreateBox invocation.

I added the following code to the area that constructs the FlowChartX control:

~~~

CY cyFontSize;
cyFontSize.int64 = 10;

FONTDESC fd;
fd.cbSizeofstruct = sizeof(FONTDESC);
fd.cySize = cyFontSize;
fd.fItalic = FALSE;
fd.fStrikethrough = FALSE;
fd.fUnderline = FALSE;
fd.lpstrName = OLESTR("Arial");
fd.sCharset = DEFAULT_CHARSET;// TODO: Maybe better to get this from the thread locale?
fd.sWeight = FW_NORMAL;

IFontDisp *iFont;
HRESULT hr = OleCreateFontIndirect(&fd, IID_IFontDisp, (void**)&iFont);
ASSERT(SUCCEEDED(hr));
OleFont font(iFont);

...
m_pFlowChart->SetFont(font);

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception Creating a Box
Reply #3 - Aug 13th, 2007 at 4:26pm
Print Post  
Hi,

Try using a larger font size. This is from the FONTDESC documentation in MSDN:

cySize
Initial point size of the font. Use the int64 parameter of the CURRENCY structure and scale your font size (in points) by 10000.

so GDI+ might throw some exception if it considers 10 a too small value.

Stoyan
  
Back to top
 
IP Logged
 
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Re: Exception Creating a Box
Reply #4 - Aug 13th, 2007 at 7:13pm
Print Post  
No luck with that.  However, I did find out something interesting.

In addition to the main FlowChartX panel, my control is building about 80 FlowChartX panels.  Those represent the different "shapes" that can be drawn on the main panel and when clicked change the main FlowChart's default shape.

If I DON'T create those, then the problem goes away.

Originally they weren't using GDI+.  I just changed them all to use GDI+ as well thinking that having two different engines running at the same time might be the problem.  However, that didn't seem to help.

Any other recommendations?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception Creating a Box
Reply #5 - Aug 14th, 2007 at 5:23am
Print Post  
You are creating 80 FlowchartX instances? I guess that could exhaust the GDI(+) resources at some point. Windows still has some limit on how many font/pen/brush handles you create in an application.
Why not create a single additional flowchart, and display all 80 shapes in it? You can change the main flowchart's default shape from the BoxClicked event raised by the helper flowchart.

Stoyan
  
Back to top
 
IP Logged
 
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Re: Exception Creating a Box
Reply #6 - Aug 14th, 2007 at 10:50am
Print Post  
I was thinking of making that exact change sometime today.

I'll let you know how it goes.
  
Back to top
 
IP Logged
 
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Re: Exception Creating a Box
Reply #7 - Aug 14th, 2007 at 11:23am
Print Post  
Actually, looking at the GDI objects through Task Manager, I'm only at 443 objects when the crash occurs.  That is far below the maximum.

As such, I'm not going to change the currently working algorithm for laying out the flowchart objects, etc.

I'm going to make sure that all the FlowChartX objects are being destroyed properly.  But at this point, it doesn't appear to be hitting the GDI resource limit.
  
Back to top
 
IP Logged
 
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Re: Exception Creating a Box
Reply #8 - Aug 14th, 2007 at 6:12pm
Print Post  
I created a small test program using MFC.

It is a dialog based application, but I changed it to be a modeless dialog instead of using the DoModal call (so that a windows message pump would execute).

In my OnIdle handler, I destroy an existing FlowChartX if I have one and then create a new one.

By loop 3 this typically crashes in the same spot my code is crashing in my application.

Code for the main class is pasted below...

The rest of the code is basically the MFC template and your pre-generated flowchart classes.

~~~~~~~~~~~~~~~~

// TestFlowChartX Creation.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "TestFlowChartX Creation.h"
#include "TestFlowChartX CreationDlg.h"
#include "CFlowChart.h"
#include "CVersionInfo.h"
#include "flowchart.h"
#include "graphics.h"
#include "boxitem.h"
#include "font.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CTestFlowChartXCreationApp

BEGIN_MESSAGE_MAP(CTestFlowChartXCreationApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()


// CTestFlowChartXCreationApp construction

CTestFlowChartXCreationApp::CTestFlowChartXCreationApp()
: m_pFlowChart(NULL)
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}


// The one and only CTestFlowChartXCreationApp object

CTestFlowChartXCreationApp theApp;


// CTestFlowChartXCreationApp initialization

BOOL CTestFlowChartXCreationApp::InitInstance()
{
CWinApp::InitInstance();

AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));

m_pDlg = new CTestFlowChartXCreationDlg();
m_pDlg->Create(CTestFlowChartXCreationDlg::IDD, NULL);
m_pMainWnd = m_pDlg;

//INT_PTR nResponse = dlg.DoModal();
//if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
//else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
}

// Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.
//return FALSE;
return TRUE;
}

BOOL CTestFlowChartXCreationApp::OnIdle(LONG lCount)
{
static unsigned int i = 0;
static CString strText;
strText.Format("%d", i++);
TRACE("Running loop %u\n...", i);

if (m_pFlowChart)
{
m_pFlowChart->GetGraphics().ShutDown();
m_pFlowChart->DestroyWindow();
delete m_pFlowChart;
m_pFlowChart = NULL;
}

CRect rc;
m_pMainWnd->GetClientRect(rc);

m_pFlowChart = new FlowChart();
m_pFlowChart->Create(NULL, WS_CHILD | WS_VISIBLE, rc, m_pMainWnd, 500, NULL);
m_pFlowChart->GetGraphics().StartUp(geGdiPlus);
m_pFlowChart->GetGraphics().SetAntiAliasing(TRUE);

BoxItem pDocBox = m_pFlowChart->CreateBox(0, 0, 100, 100);

return TRUE;
}
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception Creating a Box
Reply #9 - Aug 15th, 2007 at 5:15am
Print Post  
Please paste the header file code too, or email the test project to support@mindfusion.eu.

Stoyan
  
Back to top
 
IP Logged
 
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Re: Exception Creating a Box
Reply #10 - Aug 15th, 2007 at 11:32am
Print Post  
I'll email the project.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception Creating a Box
Reply #11 - Aug 16th, 2007 at 12:12pm
Print Post  
I have been running a few instances of the test project for half an hour and there aren't any problems, at least on my system.



What FlowChartX version are you using, and what is the build number of your gdiplus.dll?

Stoyan
  
Back to top
 
IP Logged
 
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Re: Exception Creating a Box
Reply #12 - Aug 16th, 2007 at 12:19pm
Print Post  
I am using the trial version of FlowChartX, version 4.1.4.

Gdiplus.dll is from XP (Side by Side):
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.2600.2180_x
-ww_522f9f82\GdiPlus.dll
5.1.3102.2180
  
Back to top
 
IP Logged
 
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Re: Exception Creating a Box
Reply #13 - Aug 16th, 2007 at 12:20pm
Print Post  
Release mode on my machine seemed to lock up pretty consistently.

Debug mode seemed to take 3 runs before showing the issue.

If it doesn't happen in the first few seconds of the program running, then it won't crash.
  
Back to top
 
IP Logged
 
alan_wood
YaBB Newbies
*
Offline



Posts: 16
Joined: Jul 17th, 2007
Re: Exception Creating a Box
Reply #14 - Aug 16th, 2007 at 12:33pm
Print Post  
Might be something local to my machine.

I had another developer here run the test code on their machine, and we didn't see any lockups.

After that, I removed the code from machine, installed the code from the zip file and re-ran the code.  I still crashed.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint