I have some code that programs a dialog box to take in information from an outside instrument and display the values on the screen. When I compile and run my code in Debug mode it runs just fine, but when I switch to Release the program crashes and tells me I am accessing something incorrectly. After some searching on the web I configured my compiler to run without optimizations and also tried to enable debugging info in the project configurations (for Release). However, it does not stop at breakpoints in the Release version and so troubleshooting has been difficult. I get the impression that there is something not being initialized correctly, but I cannot find the problem. Can anyone help?
Here is the implementation file for the dialog box.
#include "stdafx.h"
#include "winstm.h"
#include "Dlg_Channel_Meter.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifdef HARDWARE_NI
CDlg_Channel_Meter::CDlg_Channel_Meter(CWnd* pParent )
: CDialog(CDlg_Channel_Meter::IDD, pParent)
, m_DAC_Dev(0)
{
theInst = ((CWinSTMApp*)AfxGetApp())->GetInstrument();
m_Scan_Chan[0] = 0;
m_Scan_Chan[1] = 1;
m_Scan_Chan[2] = 2;
m_Scan_Chan[3] = 3;
m_Scan_Chan[4] = 4;
m_Scan_Chan[5] = 5;
m_Scan_Chan[6] = 6;
m_Scan_Chan[7] = 7;
m_pThread = NULL;
m_ADC0 = _T("");
m_ADC1 = _T("");
m_ADC2 = _T("");
m_ADC3 = _T("");
m_ADC4 = _T("");
m_ADC5 = _T("");
m_ADC6 = _T("");
m_ADC7 = _T("");
ticks = 0;
counts = 0;
upperlimit = 10;
for (int i = 0; i < 8; i++)
{
m_ADC_data[i]=0;
m_ADC_ddata[i]=0;
for (int c = 0; c < upperlimit; c++)
{
m_ADC_a_array[i][c] = 0;
}
}
m_ADC_a.SetSize (8);
m_ADC_std.SetSize (8);
m_ADC_a[0] = _T("");
m_ADC_a[1] = _T("");
m_ADC_a[2] = _T("");
m_ADC_a[3] = _T("");
m_ADC_a[4] = _T("");
m_ADC_a[5] = _T("");
m_ADC_a[6] = _T("");
m_ADC_a[7] = _T("");
m_ADC_std[0] = _T("");
m_ADC_std[1] = _T("");
m_ADC_std[2] = _T("");
m_ADC_std[3] = _T("");
m_ADC_std[4] = _T("");
m_ADC_std[5] = _T("");
m_ADC_std[6] = _T("");
m_ADC_std[7] = _T("");
if(AfxGetApp()->GetProfileInt("UEI DAC","Enable",0))
m_DAC_Dev = -1;
else
m_DAC_Dev = theInst->m_DAQ.m_6508_Device;
}
void CDlg_Channel_Meter::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_6052E_ADC0, m_ADC0);
DDX_Text(pDX, IDC_6052E_ADC1, m_ADC1);
DDX_Text(pDX, IDC_6052E_ADC2, m_ADC2);
DDX_Text(pDX, IDC_6052E_ADC3, m_ADC3);
DDX_Text(pDX, IDC_6052E_ADC4, m_ADC4);
DDX_Text(pDX, IDC_6052E_ADC5, m_ADC5);
DDX_Text(pDX, IDC_6052E_ADC6, m_ADC6);
DDX_Text(pDX, IDC_6052E_ADC7, m_ADC7);
DDX_Text(pDX, IDC_6052E_ADC0_a, m_ADC_a[0]);
DDX_Text(pDX, IDC_6052E_ADC1_a, m_ADC_a[1]);
DDX_Text(pDX, IDC_6052E_ADC2_a, m_ADC_a[2]);
DDX_Text(pDX, IDC_6052E_ADC3_a, m_ADC_a[3]);
DDX_Text(pDX, IDC_6052E_ADC4_a, m_ADC_a[4]);
DDX_Text(pDX, IDC_6052E_ADC5_a, m_ADC_a[5]);
DDX_Text(pDX, IDC_6052E_ADC6_a, m_ADC_a[6]);
DDX_Text(pDX, IDC_6052E_ADC7_a, m_ADC_a[7]);
DDX_Text(pDX, IDC_6052E_ADC0_std, m_ADC_std[0]);
DDX_Text(pDX, IDC_6052E_ADC1_std, m_ADC_std[1]);
DDX_Text(pDX, IDC_6052E_ADC2_std, m_ADC_std[2]);
DDX_Text(pDX, IDC_6052E_ADC3_std, m_ADC_std[3]);
DDX_Text(pDX, IDC_6052E_ADC4_std, m_ADC_std[4]);
DDX_Text(pDX, IDC_6052E_ADC5_std, m_ADC_std[5]);
DDX_Text(pDX, IDC_6052E_ADC6_std, m_ADC_std[6]);
DDX_Text(pDX, IDC_6052E_ADC7_std, m_ADC_std[7]);
DDX_Text(pDX, IDC_STATIC_CH0, theInst->m_ADC_Description[0]);
DDX_Text(pDX, IDC_STATIC_CH1, theInst->m_ADC_Description[1]);
DDX_Text(pDX, IDC_STATIC_CH2, theInst->m_ADC_Description[2]);
DDX_Text(pDX, IDC_STATIC_CH3, theInst->m_ADC_Description[3]);
DDX_Text(pDX, IDC_STATIC_CH4, theInst->m_ADC_Description[4]);
DDX_Text(pDX, IDC_STATIC_CH5, theInst->m_ADC_Description[5]);
DDX_Text(pDX, IDC_STATIC_CH6, theInst->m_ADC_Description[6]);
DDX_Text(pDX, IDC_STATIC_CH7, theInst->m_ADC_Description[7]);
}
BEGIN_MESSAGE_MAP(CDlg_Channel_Meter, CDialog)
ON_WM_TIMER()
END_MESSAGE_MAP()
BOOL CDlg_Channel_Meter::OnInitDialog()
{
CDialog::OnInitDialog();
theInst->ADC_ScanSetup(8,&m_Scan_Chan[0]);
for(int i = 0; i <8 ; i++)
{
m_6052_IO_State[i] = false;
}
SetTimer(1,100,NULL);
UpdateData(false);
return TRUE; }
void CDlg_Channel_Meter::OnTimer(UINT nIDEvent)
{
theInst->ADCread(8,m_Scan_Chan,m_ADC_data);
theInst->DAQ_VScale(m_6052_Device,8,m_ADC_data,m_ADC_ddata);
for (int i = 0; i < 8; i++)
{
m_ADC_a_array[i][counts] = m_ADC_ddata[i];
}
counts++;
ticks++;
CStatic *stat=NULL;
if (ticks >= 1)
{
m_ADC0.Format("%.4f V",m_ADC_ddata[0]);
m_ADC1.Format("%.4f V",m_ADC_ddata[1]);
m_ADC2.Format("%.4f V",m_ADC_ddata[2]);
m_ADC3.Format("%.4f V",m_ADC_ddata[3]);
m_ADC4.Format("%.4f V",m_ADC_ddata[4]);
m_ADC5.Format("%.4f V",m_ADC_ddata[5]);
m_ADC6.Format("%.4f V",m_ADC_ddata[6]);
m_ADC7.Format("%.4f V",m_ADC_ddata[7]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC0);
stat->SetWindowText(m_ADC0);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC1);
stat->SetWindowText(m_ADC1);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC2);
stat->SetWindowText(m_ADC2);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC3);
stat->SetWindowText(m_ADC3);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC4);
stat->SetWindowText(m_ADC4);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC5);
stat->SetWindowText(m_ADC5);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC6);
stat->SetWindowText(m_ADC6);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC7);
stat->SetWindowText(m_ADC7);
ticks = 0;
}
if (counts >= upperlimit)
{
double average[8];
double std[8];
for (int i = 0; i < 8; i++)
{
average[i] = 0;
std[i] = 0;
}
for (int i = 0; i < 8; i++)
{
for (int c = 0; c < upperlimit; c++)
{
average[i] += m_ADC_a_array[i][c];
}
average[i] = average[i] / upperlimit;
for (int c = 0; c < upperlimit; c++)
{
double diff = (average[i] - m_ADC_a_array[i][c]);
std[i] += (diff * diff);
}
std[i] = sqrt(std[i] / upperlimit);
m_ADC_a[i].Format("%.4f V",average[i]);
m_ADC_std[i].Format("%.4f V",std[i]);
}
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC0_a);
stat->SetWindowText(m_ADC_a[0]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC1_a);
stat->SetWindowText(m_ADC_a[1]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC2_a);
stat->SetWindowText(m_ADC_a[2]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC3_a);
stat->SetWindowText(m_ADC_a[3]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC4_a);
stat->SetWindowText(m_ADC_a[4]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC5_a);
stat->SetWindowText(m_ADC_a[5]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC6_a);
stat->SetWindowText(m_ADC_a[6]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC7_a);
stat->SetWindowText(m_ADC_a[7]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC0_std);
stat->SetWindowText(m_ADC_std[0]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC1_std);
stat->SetWindowText(m_ADC_std[1]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC2_std);
stat->SetWindowText(m_ADC_std[2]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC3_std);
stat->SetWindowText(m_ADC_std[3]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC4_std);
stat->SetWindowText(m_ADC_std[4]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC5_std);
stat->SetWindowText(m_ADC_std[5]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC6_std);
stat->SetWindowText(m_ADC_std[6]);
stat = (CStatic*)GetDlgItem(IDC_6052E_ADC7_std);
stat->SetWindowText(m_ADC_std[7]);
for (int i = 0; i < 8; i++)
{
for (int c = 0; c < upperlimit; c++)
{
m_ADC_a_array[i][c] = 0;
}
}
counts = 0;
}
}
#endif // #ifdef HARDWARE_NI