AC16.11 – TsSaveDialog, TsSavePictureDialog, etc… Crash under debugger

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #70119
    Support
    Keymaster

    Hello!
    I can’t repeat it unfortunately, maybe some another condition is required..
    Is it possible to make a demo with this error?
    Which Delphi version do you use?

    #70124
    UniSoft
    Participant

    Windows 7
    RAD 10.4 with last 2 updates

    By the way, bug with GripPos is not fixed

    function TsStatusBar.GripPos: TPoint;
    begin
      if FCommonData.SkinManager <> nil then
        with FCommonData.SkinManager, SkinData.CommonSkinData do
          if IsValidImgIndex(GripRightBottom) then begin
            Result := Point(Width - ma[GripRightBottom].Width - BorderWidth, Height - ma[GripRightBottom].Height - BorderWidth);
            Exit;
          end;
    
      Result := Point(Width - GetSystemMetrics(SM_CXSIZEFRAME), Height - GetSystemMetrics(SM_CYSIZEFRAME));
    end;
    #70125
    UniSoft
    Participant

    I tried to make demo, but it is crashed only under debugger
    First I commented try..except
    then compile release version…
    if I run it from rad studio in debugger, then it crash…
    If I open exe in any debugger (OllyDbg, x64dbg, …) they catch Access Violation…

    function TacMainWnd.CallPrevWndProc(const Handle: hwnd; const Msg: longint; const WParam: WPARAM; var LParam: LPARAM): LRESULT;
    var
      M: TMessage;
    begin
      if Assigned(OldWndProc) then begin
        M.Msg := Msg;
        M.WParam := WParam;
        M.LParam := LParam;
        M.Result := 0;
        OldWndProc(M);
        Result := M.Result;
        LParam := M.LParam;
      end
      else
        if Assigned(OldProc) then
          //try
            Result := CallWindowProc(OldProc, Handle, Msg, WParam, LParam)
          //except
          //  Result := 0;
          //end
        else
          Result := 0;
    end;

    Alternate link to demo (with compiled exe)
    __https__://mega.nz/file/xO5BiQpJ#MRE7uX5rWFFbe1gKJ8snE1Fruj8XJiXfuKUqxXNcP_g

    Attachments:
    You must be logged in to view attached files.
    #70127
    UniSoft
    Participant

    I found problem…
    “AnVir Task Manager” adds an icon to the tool bar of open/save dialog and it is the reason why it crash.
    But anyway strange, if to disable skinning, then there is no crash.
    BTW, message 1046 – probably TB_DELETEBUTTON
    shit.. and I had this problem before, just forgot :(.

    #70130
    UniSoft
    Participant

    This helps to solve that crash
    comment WM_DESTROY
    What for need to process both WM_DESTROY and WM_NCDESTROY?
    WM_NCDESTROY is the last one, so should be enough.

    procedure TacDialogWnd.acWndProc(var Message: TMessage);
    var
      PS: TPaintStruct;
      X, Y, i: integer;
      cR, rClient: TRect;
    begin
      case Message.Msg of
        {WM_DESTROY,} WM_NCDESTROY: begin
          if SkinData.FCacheBmp <> nil then
            SkinData.FCacheBmp.Assign(nil);
      ...
        end;
    #70132
    UniSoft
    Participant

    just some explain, what doing AnVir, now you can see why it cause crash

      case Msg of
      WM_DESTROY, WM_CLOSE: 
        begin
          // here is the problem!!! 
          // this call should be after clean up, not before
          CallWindowProc(PrevWndFunc, ...); // !!!
    
         // After called Destructor all bottom crap can cause an error
    	  
          // this called on init time, then add custom buttons
          //  so btncount cotaint number of buttons in toolbat before add new buttons
          //btncount := SendMessageA(Handle, TB_BUTTONCOUNT, 0, 0); //
    	  
          // restore previous WndProc
          SetWindowLong(Handle, GWLP_WNDPROC, PrevWndFunc);
    	  
          // delete custom buttons
          SendMessageA(Handle, TB_DELETEBUTTON, btncount + 1, 0);
          SendMessageA(Handle, TB_DELETEBUTTON, btncount    , 0);
        end;
      end;
    #70137
    Support
    Keymaster

    Hello!
    I have found a potential reason of the problem there.
    Plz, wait a new release and check it (v16.12).
    Or, I can send you a patched unit if you have sources of the package.

    #70140
    UniSoft
    Participant

    Up to you
    If you need I can check it before release…

    #70142
    UniSoft
    Participant

    Hello!
    I Checked v16.12
    still have the same crash… 🙁

    I can clearly see in the debugger what exactly is going on…
    Look

    1. AC sets the new Window Pointer

       InitializeACWnd
          OldProc := Pointer(GetWindowLong(CtrlHandle, GWL_WNDPROC));
          NewWndProcInstance := {$IFDEF DELPHI6UP}Classes.{$ENDIF}MakeObjectInstance(acWndProc);
          SetWindowLong(CtrlHandle, GWL_WNDPROC, LONG_PTR(NewWndProcInstance));

    2. Now AnVir do the same (and saves OldProc which is actually already = NewWndProcInstance)
    3. Closing Dialog
    4. Get message WM_DESTROY (Notice! it doesn’t get WM_CLOSE, at least I don’t see it in WinSpy)
    Now the AnVir first pass processing to the old wndProc (what is actually = NewWndProcInstance!)
    on process of WM_DESTROY – AC restores original OldProc, after that AC deletes NewWndProcInstance
    FreeObjectInstance(ListSW.NewWndProcInstance);

       procedure UninitializeACWnd(...
            if Assigned(ListSW.OldProc) then begin
              SetWindowLong(Handle, GWL_WNDPROC, LONG_PTR(ListSW.OldProc));
              ListSW.OldProc := nil;
              if Assigned(ListSW.NewWndProcInstance) then begin
                {$IFDEF DELPHI6UP}Classes.{$ENDIF}FreeObjectInstance(ListSW.NewWndProcInstance);
                ListSW.NewWndProcInstance := nil;
              end;
            end

    5. process returns back to the AnVir, where this shit also thinking that restores old WndProc
    SetWindowLong(Handle, GWLP_WNDPROC, PrevWndFunc);
    BUT! it is a pointer to already deleted NewWndProcInstance
    And follow send the messages

            SendMessageA(Handle, TB_DELETEBUTTON, btncount + 1, 0);
             SendMessageA(Handle, TB_DELETEBUTTON, btncount    , 0);

    That is the actually reason!


    BUG with StatusBar still not fixed as well 🙁
    to see it:
    1. Launch ASkinDemo.exe
    2. Select skin: Standard theme
    3. Move cursor over StatusBar
    Fixed code is few posts up…

    #70168
    Support
    Keymaster

    Thanks for researching, I will check how to avoid this situation.
    And StatusBar in standard non-skinned mode will be fixed in the nearest release.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.