Bläddra i källkod

Stabilize painting/threading and image scaling

- Guard background tiling when resource missing or 0 size\n- Avoid potential Synchronize deadlock by polling CheckSynchronize while stopping worker\n- Rescale book cover after setting final size on add\n- Use FileExistsUTF8 when loading XML
Codex CLI 4 månader sedan
förälder
incheckning
4726538b91
3 ändrade filer med 13 tillägg och 2 borttagningar
  1. 6 0
      src/main.pas
  2. 6 1
      src/unitCoverWorker.pas
  3. 1 1
      src/unitStorageXML.pas

+ 6 - 0
src/main.pas

@@ -112,6 +112,10 @@ procedure TForm1.PanelBackgroundPaint({%H-}Sender: TObject);
 var w,h:Integer;
     x,y:Integer;
 begin
+  // Safety: if no tile or invalid size, skip custom painting
+  if (backgroundTile = nil) or (backgroundTile.Width <= 0) or (backgroundTile.Height <= 0) then
+    Exit;
+
   x:=0;
   y:=0;
   w:=backgroundTile.Width;
@@ -382,6 +386,8 @@ var
     book.Cover.Width:=coverWidth;
     book.Cover.Height:=coverHeight;
     book.Cover.Parent:=PanelBackground;
+    // Ensure the pre-scaled image matches the final cover size
+    book.EnsureScaledToCoverSize;
     CoverWorkerEnqueueBookIfMissing(book);
   end;
 

+ 6 - 1
src/unitCoverWorker.pas

@@ -190,7 +190,12 @@ begin
   if GWorker <> nil then
   begin
     GWorker.Terminate;
-    GWorker.WaitFor;
+    // Process synchronize calls while waiting to avoid potential deadlock
+    while not GWorker.Finished do
+    begin
+      Classes.CheckSynchronize(10);
+      Sleep(5);
+    end;
     GWorker := nil;
   end;
   if GPdfQueue <> nil then

+ 1 - 1
src/unitStorageXML.pas

@@ -49,7 +49,7 @@ var
 begin
   if (aList = nil) or (Parent = nil) then Exit;
 
-  if not FileExists(FileName) then
+  if not FileExistsUTF8(FileName) then
   begin
     // Nothing to load; ensure list is empty
     if aList.Count > 0 then