繁体   English   中英

我不了解调用堆栈中重复的DispatchMessageW的堆栈溢出错误

[英]I don't understand stack overflow error with repeated DispatchMessageW in the call stack

这是一个Delphi应用程序,但我想这是一个常见的Windows编程问题。

我在周末让我的应用程序运行(在Delphi IDE中),然后刚回来发现堆栈溢出。

堆栈像这样开始...

:75c4417e kernel32.GetDriveTypeW + 0x23
:75c452ae kernel32.IsProcessorFeaturePresent + 0xa9
:75c45272 kernel32.IsProcessorFeaturePresent + 0x6d
:75c45248 kernel32.IsProcessorFeaturePresent + 0x43
:7678410b KERNELBASE.LoadStringBaseExW + 0xc7
:76678ed2 USER32.LoadStringW + 0x19
:0040c4ae LoadResString + $4A
uADStanDef.TADDefinition.Create(nil)
uADStanDef.TADDefinition.CreateTemporary
uADStanDef.TADConnectionDefTemporaryFactory.CreateObject
uADStanFactory.TADManager.CreateInterface((1050358107, 62550, 16757, (168, 100, 178, 87, 60, 74, 32, 21)),(no value),True)
uADStanFactory.ADCreateInterface((1050358107, 62550, 16757, (168, 100, 178, 87, 60, 74, 32, 21)),(no value),True)
uADCompClient.TADCustomConnection.Create($2DB7EB0)
fMainForm.TMainForm.ServerAliveTimerTimer($2E8DE38)    <========== my code
:004f1546 Winapi + $4F1546
:00461316 Winapi + $461316
:766762fa ; C:\Windows\syswow64\USER32.dll
:76676d3a USER32.GetThreadDesktop + 0xd7
:766777c4 ; C:\Windows\syswow64\USER32.dll
:7667788a USER32.DispatchMessageW + 0xf

因此,一个计时器即将到期,我正在创建一个(AnyDac组件的)新对象,并且堆栈溢出。 该代码肯定会释放对象。 我在下面附加了要检查的内容,但我认为这不是我的问题。

然后堆栈继续

:7669cdfd ; C:\Windows\syswow64\USER32.dll
:7669cf5c ; C:\Windows\syswow64\USER32.dll
:766cf73c ; C:\Windows\syswow64\USER32.dll
:766cfa18 ; C:\Windows\syswow64\USER32.dll
:766cfb1f USER32.MessageBoxTimeoutW + 0x52
:766cfd15 USER32.MessageBoxExW + 0x1b
:766cfd57 USER32.MessageBoxW + 0x18
:00549986 Vcl + $549986
:00549aa2 Vcl + $549AA2
:00549873 Vcl + $549873
:00461316 Winapi + $461316
:766762fa ; C:\Windows\syswow64\USER32.dll
:76676d3a USER32.GetThreadDesktop + 0xd7
:766777c4 ; C:\Windows\syswow64\USER32.dll
:7667788a USER32.DispatchMessageW + 0xf

重复执行该块三千行(!),我不知道它是什么或正在做什么。 然后结束

StoreRoom.StoreRoom
:75c4339a kernel32.BaseThreadInitThunk + 0x12
:77eb9ef2 ntdll.RtlInitializeExceptionChain + 0x63
:77eb9ec5 ntdll.RtlInitializeExceptionChain + 0x36

我不理解所有重复的内容-有人可以建议吗?

(对于那些注意到我的异常处理正在显示一个对话框的人来说,这是一个机敏的人,这是一个TForm,当用户单击“确定”时,它会关闭)

我的代码:

procedure TMainForm.ServerAliveTimerTimer(Sender: TObject);
begin
   try
      ADConnection := TADConnection.Create(Self);  <======= stack overflow here
      ADConnection.DriverName := 'mysql';
      ADConnection.Params.Add('Server=' + MAIN_STOREROOM_IP_ADDRESS);  
      // other params, such as password, removed for posting
      ADConnection.Connected := True;

   except
      on E : Exception do
      begin
         ADConnection.Free();
         theDialogForm := TDialogFormForm.Create(Nil);
         theDialogForm.ShowTheForm('Database problem'+#13+#10+''+#13+#10+
                                   E.ClassName+#13+#10+E.Message);    
         StopTheApplication();   <===== just calls ExitProcess(0);
         Exit;                     as I had problems with Halt elsewhere in the code
      end;
   end;

   if isMainStoreRoom then
   begin
      CheckIfStoreRoomIsAlive(SECONDARY_STOREROOM_IP_ADDRESS);
   end
   else
   begin
      CheckIfStoreRoomIsAlive(MAIN_STOREROOM_IP_ADDRESS);
   end;

   try    // Now, update our own timestamp
      timestamp  := GetCurrentUnixTimeStamp();
      ADConnection.ExecSQL('UPDATE server_status SET alive_timestamp="' + IntToStr(timestamp) + '" WHERE ip_address="' + ipAddress + '"');

   except
      on E : Exception do
      begin
         ADConnection.Free();
         Exit;
      end;
   end;

   ADConnection.Free();
end;     // ServerAliveTimerTimer()

您的堆栈溢出是由于MessageBox()一遍又一遍地响应重复的窗口消息而被调用的。 在内部, MessageBox()运行自己的消息循环,显然是一遍又一遍地处理和分发相同的消息。 这可能表明计时器已误入歧途。 我强烈建议您在首次进入OnTimer事件处理程序时禁用计时器,然后在退出前重新启用计时器。

另外, StopTheApplication()不应直接调用ExitProcess() (甚至是Halt() )。 使用Application.Terminate()代替。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM