lazpaint icon indicating copy to clipboard operation
lazpaint copied to clipboard

Unhandled exception! Cannot close active tool. Deformation Grid.

Open trebor048 opened this issue 1 year ago • 8 comments

Error popup says: "Message: Conflicting actions"

I've had this issue a handful of times over the past few months. And today I've pin-pointed why, and triple checked that this sequence of events causes it. Each time forcing me into an endless loop of trying to select another tool, only to get an error.. Which it only stopped by forcefully closing the program and losing the current edits.

- Press M, Rectangle Select an area

- Press J

- Click Deformation grid

Unhandled exception happens

trebor048 avatar Jul 29 '24 08:07 trebor048

Thank you very much for the detailled steps. I'll look into it.

circular17 avatar Aug 27 '24 06:08 circular17

I've applied the steps you proposed, however the exception did not happen. Does it need to open a specific file?

Regards

circular17 avatar Aug 27 '24 06:08 circular17

Attached are some videos how to replicate the problem (how I understood it).

Regards

https://github.com/user-attachments/assets/7d06cdc7-07a6-44af-8357-f534514f14e0

https://github.com/user-attachments/assets/5b9c46c6-f6a2-4a67-8680-467bdc8abf06

melchiorrecaruso avatar Sep 01 '24 12:09 melchiorrecaruso

Oh ok, thank you, the video helped me understand the steps. I've been able to replicate it now.

It is now fixed on dev.

Regards

circular17 avatar Sep 05 '24 13:09 circular17

Hello Circular,

there is still something to fix regarding this patch. Now on Linux (GTK2), after pressing the "Deformation Grid" button, the image disappears. The image reappears if the screen is refreshed.

I have attached another video.

Your patch works correctly on Windows.

Best regards, Melchiorre

https://github.com/user-attachments/assets/bf0687ff-7df6-4430-b1e5-58dbb6ac971e

melchiorrecaruso avatar Sep 05 '24 17:09 melchiorrecaruso

Hello Melchiorre,

I am not sure why the window is cleared. However here are are some patches that comes to mind that could work. Can you give it a try?

Maybe this could be patched by returning a non empty rectangle in the TToolDeformationGrid.Render function. On line 1228 of UToolDeformationGrid.pas, by changing the exit instruction:

begin
  result := EmptyRect;
  if (VirtualScreen = nil) and (deformationGrid = nil) then
    exit(rect(0, 0, VirtualScreenWidth, VirtualScreenHeight));

Otherwise, another patch would be to explicitly refresh the window in TFMain.ScriptChooseTool. For example by adding on line 3151 in LazPaintMainForm.pas before the except keyword:

      {$IFDEF LINUX}If Tool = ptDeformation then Invalidate;{$ENDIF}
    except

Warm regards

circular17 avatar Sep 08 '24 04:09 circular17

Both patches are not working.

I think that in the second patch the Invalidate method is called at the wrong time, when everything is not yet ready to update the form.

The second patch works if I add an 'Application.ProcessMessages':

  {$IFDEF LINUX}   
  if Tool = ptDeformation then  
  begin
    Application.ProcessMessages;
    Invalidate;
  end;
  {$ENDIF}
except

or if I use a Timer to call Invalidate at a later time.

    {$IFDEF LINUX}
    if Tool = ptDeformation then
    begin
      Timer1.Enabled := True;
    end;
    {$ENDIF}
  except

I hope this can be helpful. Best regards

melchiorrecaruso avatar Sep 08 '24 19:09 melchiorrecaruso

Thank you very much for trying these patches. So Invalidate cannot be called at this moment. I'll consider your proposals to determine the one to apply.

Warm regards

circular17 avatar Sep 11 '24 19:09 circular17