When OnHasPhase returns, it calls the destructor in samples
Last reviewed: 6/8/1999
PRB Article ID: P069901
The information in this article applies to:
- SpeechKit 2.1
Symptoms
I am using speech kit 2.1 with VC++ 6.0. When the function OnHasPhase returns, it calls the destructor of that class. I tested it with the DriveThru sample. I added destructor to CDrvthruDlg and each time the function OnHasPhase returns, it calls the destructor. The problem is when the destructor has code like delete allocated memory.
Cause
It is not caused by HasPhrase callback, but rather how Drvthru and Eticket are using a branch table to invoke the member for particular commands. If you add the deconstructor to the number sample, the hasPhrase does not use a branch table, and does not generate this problem with the deconstructor.
Status
Fixed. Here is the fix. Four lines are affected as noted:
// Process recognized phrase.
void CDrvthruDlg::OnHasPhrase(LPTSTR pszPhrase)
{
// Private - Set the system status.
int quantity, i;
_TCHAR *qString, *item;
CDrvthruDlg *pStaticDlg; // *****CHANGE
// Since we are not using a sleep vocabulary, if we are not in listening mode,
// only accept Ready To Order utterance.
if (!(IsListening() || (_tcscmp(pszPhrase,SZREADYTOORDER) == 0))) {
return;
}
StopTimer();
// See if order is complete.
if ((_tcscmp(pszPhrase,SZTHATISIT) == 0) || (_tcscmp(pszPhrase,SZTHATISALL) == 0)) {
StatusNotReady();
FinishOrder();
return;
}
pStaticDlg = this; //*****ADD
// Look up order in command table.
for (i = 0; i <m_varCommandTable->GetSize(); i++) {
if ((m_varCommandTable->GetAt(i).Compare(pszPhrase)) == 0) {
(pStaticDlg->*m_varFunctionTable[i])(1, this); //*****CHANGE
StatusReady();
return;
}
}
// If utterence not found as is, then probably it contains a number prefix.
qString = _tcstok(pszPhrase,_T(" "));
if (qString == NULL) {
// Done, return finished.
StatusReady();
return;
}
item = _tcstok(NULL,_T("\0"));
quantity = _ttoi(qString);
for (i = 0; i <m_varCommandTable->GetSize(); i++) {
if ((m_varCommandTable->GetAt(i).Compare(item)) == 0) {
(pStaticDlg->*m_varFunctionTable[i])(quantity, this); //*****CHANGE
StatusReady();
return;
}
}
StatusReady();
return;
}