bgrabitmap / lazpaint

🎨 Cross-platform image editor with raster and vector layers similar to Paint.Net written in Lazarus (Free Pascal)
https://lazpaint.github.io/
GNU General Public License v3.0
406 stars 57 forks source link

Unhandled exception! Cannot close active tool. Deformation Grid. #586

Open trebor048 opened 4 months ago

trebor048 commented 4 months ago

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

circular17 commented 3 months ago

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

circular17 commented 3 months ago

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

Regards

melchiorrecaruso commented 2 months ago

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

circular17 commented 2 months ago

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

melchiorrecaruso commented 2 months ago

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

circular17 commented 2 months ago

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.Renderfunction. 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

melchiorrecaruso commented 2 months ago

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

circular17 commented 2 months ago

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