【问题标题】:Delphi XE5 Acces Violation on app startDelphi XE5 在应用程序启动时访问违规
【发布时间】:2013-12-15 21:51:57
【问题描述】:

在两台计算机上是可以的,在三台计算机上存在相同的异常,具有相同的 AV 地址。感谢帮助

begin
  Application.Hinthidepause := 30000;
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.CreateForm(TForm3, Form3);
  Application.CreateForm(TForm4, Form4);
  Application.Run;
end;

exception class    : EAccessViolation
exception message  : Access violation at address 00405361 in module 'Project1.exe'. Read of address 00000064.

main thread ($1d44):
00405361 +3d Project1.exe System         75  +0 SysGetMem
00406827 +3f Project1.exe System         75  +0 @ReallocMem
0040c38c +d8 Project1.exe System         75  +0 DynArraySetLength
0040c4bd +05 Project1.exe System         75  +0 @DynArraySetLength
005465af +23 Project1.exe System.Classes        {System.Generics.Collections}TList<System.Generics.Collections.TList<System.Classes.TComponent>>.SetCapacity
005466b0 +2c Project1.exe System.Classes        {System.Generics.Collections}TList<System.Generics.Collections.TList<System.Classes.TComponent>>.Grow
005466d2 +16 Project1.exe System.Classes        {System.Generics.Collections}TList<System.Generics.Collections.TList<System.Classes.TComponent>>.GrowCheck
00546a4d +0d Project1.exe System.Classes        {System.Generics.Collections}TList<System.Generics.Collections.TList<System.Classes.TComponent>>.Add
0051e75e +36 Project1.exe System.Classes        BeginGlobalLoading
0051e8de +46 Project1.exe System.Classes        InitInheritedComponent
0064cfde +c6 Project1.exe Vcl.Forms             TCustomForm.Create
00657ffa +76 Project1.exe Vcl.Forms             TApplication.CreateForm
00883ce7 +c7 Project1.exe Project1  54 +13 initialization
76a13368 +10 kernel32.dll 

更新 这个过程有问题:

procedure KopiujRTF(const Source, destination: TRichEdit);
var
  rtfStream: TEditStream;
  sourceStream: TMemoryStream;
  function EditStreamReader(dwCookie: DWORD; pBuff: Pointer; cb: LongInt;
    pcb: PLongInt): DWORD; stdcall;
  begin
    Result := $0000;
    try
      pcb^ := TStream(dwCookie).Read(pBuff^, cb);
    except
      Result := $FFFF;
    end;
  end;
begin
  destination.Lines.BeginUpdate;
  sourceStream := TMemoryStream.Create;
  try
    Source.Lines.SaveToStream(sourceStream);
    sourceStream.Position := 0;
    destination.MaxLength := destination.MaxLength + sourceStream.Size;
    rtfStream.dwCookie := DWORD(sourceStream);
    rtfStream.dwError := $0000;
    rtfStream.pfnCallback := @EditStreamReader;
    destination.Perform(EM_STREAMIN, SFF_SELECTION or SF_RTF or SFF_PLAINRTF,
      lParam(@rtfStream));
    if rtfStream.dwError <> $0000 then
      zolty := True;
    sourceStream.Free;
    destination.Lines.EndUpdate;
  except
  end;
end;

在 form1 创建我有:

RichEdit1.MaxLength := $7FFFFFF0;

启用范围检查调试器后突出显示:

destination.MaxLength := destination.MaxLength + sourceStream.Size;

删除 RichEdit 的最大长度已解决问题。感谢您的帮助。

【问题讨论】:

  • 您的调用堆栈表明在 DFM 流式传输期间正在访问 nil TList 指针。
  • @RemyLebeau 不,这是一个错误的分析。 AV 将在此之前很久。它将发生在TList&lt;T&gt;.Add 读取FCount 以形成传递给GrowCheck 的参数。
  • AV 的地址足够低,表明某个地方正在访问一个 nil 指针。如果在无效的TList&lt;T&gt; 上调用Add(),那么显然它的FCount 将不会保持有效计数,并且它将在无效的动态数组上调用SetLength()
  • @Remy 调用堆栈明显是堆损坏。你肯定认出来了吗?

标签: delphi delphi-xe5


【解决方案1】:

调用堆栈表明您在程序的其他部分损坏了堆。这就是SysGetMem 中的访问冲突的解释,概率 > 0.999。

在执行此调用堆栈中的代码之前,您需要查看启动期间发生的情况。查找缓冲区溢出,即访问越界数组元素。很有可能仅仅启用必不可少的range checking 功能就足以定位您的程序的缺陷。

【讨论】:

  • 感谢您的回答。会尝试,一个问题是在我的电脑上一切正常。
  • 这在堆损坏中很常见。它们通常是不可重复的。您必须使用范围检查,至少用于调试构建。这是一个非常棒的功能。
  • 我一直想知道为什么人们在开发过程中不这样做——尤其是在发生错误时。
  • @UweRaabe 我猜是因为人们没有意识到这一点。为什么 Emba 不在调试配置中默认启用它?
  • 好吧,我在项目选项中启用了范围检查,但一切正常。
【解决方案2】:

我有同样的问题,我发现问题出在版本的定义上。 打开版本信息,发现没有包含版本,无法包含。 解决方案是重新创建构造配置。

【讨论】:

    猜你喜欢
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多