Jump to content

dkprojektai

Members
  • Content Count

    61
  • Joined

  • Last visited

Posts posted by dkprojektai


  1. Hello, need help.

     

    How can I find in Delphi pointer to memory buffer which contain image file data and size of memory buffer in bytes ?

     

    These are not correct:

    @Bitmap1

    Bitmap1.ScanLine[0]

     

    Buffer size can be found:

    function GetGraphicSize(g: TGraphic): Integer;
    var
      ms: TStream;
    begin
      ms := TMemoryStream.Create;
      try
        g.SaveToStream(ms);
        Result := ms.Size;
      finally
        ms.Free;
      end;
    end;

     

    How can do it correctly ?

     

     

     


  2. Quote

    And I don't know whether or not the lock/unlock is necessary. Why did you include it?

     

    As for checking whether or not it worked, there's no point. What failure more do you have in mind? 

    1. because it's in thread;

    2. this saved picture later uses external dll library, and it sometimes make failure. That is why I thought - I need double check jpg. Unfortunately I did not found any solution on the net. 


  3. Hello, I have this code in thread:

     

    Try
      MotionBitmap1.Canvas.Lock;
      jpeg:= TJPEGImage.Create;
      jpeg.Assign(MotionBitmap1);
      jpeg.SaveToFile('D:\picture.jpg');
    finally
      MotionBitmap1.Canvas.Unlock;
      Try FreeAndNil(jpeg); except end;
    end;

     

    I'd like to find out is it saved correctly and the image is in correct format and etc. 

     

    Is there any solution to validate file?

     


  4. I'll try to do Lock and UnLock everywhere where I will use bitmap before freeing it. 

     

     straight Win32 API calls - can I get any example?

     

    I would like escape using Pascal library like graphics32 because then I will have to do many conversations. And this will impact to speed.


  5. I use Deleaker:

     

    Program.exe!@System@@GetMem$qqri Line 4738 004075b0
    Program.exe!@System@@NewUnicodeString$qqri Line 24650 0040c632
    Program.exe!@Vcl@Graphics@TFont@GetHandle Line 2600 + 0xaadfa bytes 0058a6ca
    Program.exe!@Vcl@Graphics@TCanvas@CreateFont Line 4230 + 0xacbea bytes 0058c4ba
    Program.exe!@Unit1@TWorkerThread@Execute Line 10849 + 0xec3928 bytes 013a31f8
    Program.exe!@Madexcept@HookedTThreadExecute$qqrpvt1 + 0x9c9ff bytes 004b0dab
    Program.exe!@System@Classes@ThreadProc$qqrxp22System@Classes@TThread Line 14945 + 0x60395 bytes 0053fc65
    Program.exe!@System@ThreadWrapper$qqspv Line 24423 0040c580
    Program.exe!@Madexcept@CallThreadProcSafe$qqspvt1 + 0x9c8e5 bytes 004b0c91
    Program.exe!@Madexcept@ThreadExceptFrame$qqsp21Madexcept@TThreadInfo + 0x9c94a bytes 004b0cf6
    KERNEL32.DLL!BaseThreadInitThunk + 0x17 bytes 776e0417
    ntdll.dll!RtlGetAppContainerNamedObjectPath + 0xeb bytes 7781662b
    ntdll.dll!RtlGetAppContainerNamedObjectPath + 0xb8 bytes 778165f8
    00000000 00000000

     


  6. Hello I have memory leaks in thread. Need help to fix them:

    1.

              NewBitmap:= TBitmap.Create;
              NewBitmap.Canvas.Lock;
              NewBitmap.PixelFormat:= pf24bit;
              NewBitmap_first.Canvas.Lock;
              Try
                NewBitmap.Width:= StrToInt(Detector_scan_right) - StrToInt(Detector_scan_left); 
                NewBitmap.Height:= StrToInt(Detector_scan_bottom) - StrToInt(Detector_scan_top);
                NewBitmap.Canvas.CopyRect(NewBitmap.Canvas.ClipRect, NewBitmap_first.Canvas, Rect( <<<<< memory leak
                StrToInt(Detector_scan_left),
                StrToInt(Detector_scan_top),
                StrToInt(Detector_scan_right),
                StrToInt(Detector_scan_bottom)
                ));
              Finally
                NewBitmap.Canvas.Unlock;
                NewBitmap_first.Canvas.Unlock;
              End;

    2.

    Tekst_string:= StringReplace(Tekst_string, 'data', '', [rfReplaceAll, rfIgnoreCase]);

     

    Thanks in advance. 

    Delphi 10.2


  7. Hi, made tests and finally find out how works error handling in Omnithread parallel.for. Here is my testing:

     

    procedure TbtnParallelFor.btnParallelForExceptionClick(Sender: TObject);
    var
      i: Integer;
      Loking_elem: TOmniMREW;
      Error_stack_text: string;
    begin
    
      Error_stack_text:= '';
    
          Parallel.For(0, 10,1).Execute(
          procedure (i: integer)
          begin
            Try
              
    		//What will happen if here will be error from dll???
    
    
              if i = 4 then 
              try
    
              finally
                integer(nil^):= 0;
              end;
    
              if i = 5 then
              integer(nil^):= 0;
              raise Exception.Create('Exception in thread ' +
                TThread.Current.ThreadID.ToString);
            except
    
              on E: Exception do begin
                Try
                  if i = 5 then
                  integer(nil^):= 0;
                  Loking_elem.EnterWriteLock;
                  Error_stack_text:= Error_stack_text + #13#10 + '---' + E.StackTrace;
                  Loking_elem.ExitWriteLock;
                except
                  on E: Exception do begin
                    Loking_elem.EnterWriteLock;
                    Error_stack_text:= Error_stack_text + #13#10 + '---' + E.StackTrace;
                    Loking_elem.ExitWriteLock;
                  end;
                end;
              end;
            end;
          end);
    
    
      Memo1.Lines.Text:= Error_stack_text;
    end;

     

    In my application (not in this example) I still getting application terminate on error and I can't cache it. I work with many dll's in commented section. I want to ask, what will happen if in there will be an error from dll? Is there any solution to cache it?

     

    Fault Offset:

    Faulting application name: Application.exe, version: 4.6.0.0, time stamp: 0x5d7fec1f
    Faulting module name: KERNELBASE.dll, version: 6.2.9200.16384, time stamp: 0x5010ac2f
    Exception code: 0xe06d7363
    Fault offset: 0x00014b32
    Faulting process id: 0x31c0
    Faulting application start time: 0x01d56d40dd25c4a4
    Faulting application path: C:\Application.exe
    Faulting module path: C:\Windows\SYSTEM32\KERNELBASE.dll
    Report Id: 3ff93c8d-d950-11e9-93fa-0a94ef1b475e
    Faulting package full name: 
    Faulting package-relative application ID: 

    Leads me to:

    Found:
      Provider: TELDebugInfoMap
      Location: (00C63D20){ANPR_VID.exe     } [06483D20] OtlParallel.TOmniParallelSimpleLoop.Execute[2]$ActRec.$0$Body (Line 3440, "OtlParallel.pas" + 16) + $0
        Unit: OtlParallel
        Source: OtlParallel.pas
        Class: TOmniParallelSimpleLoop.Execute[2]$ActRec
        Routine: $0$Body
        Line: 3440
    
        Routine offset (bytes): 96
        Routine offset (lines): 16
        Line offset (bytes): 0

    That is why I think that error rises dll and parallel.for is not able to handle it. Any comments are welcome.


  8. This is an exception in Parallel.for

     

    0052a796 VID_full.exe System.Classes       TStrings.LoadFromStream
    0052a71f VID_full.exe System.Classes       TStrings.LoadFromStream
    0052a68f VID_full.exe System.Classes       TStrings.LoadFromFile
    012eb693 VID_full.exe Unit1          12308 MyFind
    012eb8a9 VID_full.exe Unit1          12397 TWorkerThread.Execute$ActRec.$3$Body
    011af3f6 VID_full.exe OtlParallel     3440 TOmniParallelSimpleLoop.Execute[2]$ActRec.$0$Body
    011aefe2 VID_full.exe OtlParallel     3380 TOmniParallelSimpleLoop.CreateForTask$ActRec.$0$Body
    0118a1bb VID_full.exe OtlTaskControl  1991 TOmniTaskExecutor.Asy_Execute
    01189219 VID_full.exe OtlTaskControl  1584 TOmniTask.InternalExecute
    01188ff2 VID_full.exe OtlTaskControl  1502 TOmniTask.Execute
    0117bda2 VID_full.exe OtlThreadPool    889 TOTPWorkerThread.ExecuteWorkItem
    0117b92b VID_full.exe OtlThreadPool    846 TOTPWorkerThread.Execute
    0040c580 VID_full.exe System            25 ThreadWrapper
    004ae119 VID_full.exe madExcept            CallThreadProcSafe
    004ae17e VID_full.exe madExcept            ThreadExceptFrame
    752f8541 KERNEL32.DLL                           BaseThreadInitThunk

     

    it rises on this function:

     

    // FindInFile: Returns the position where the string to search was found
    Function MyFind(Key: String): String;
    var
      List, LineList: TStringList;
      I, x: Integer;
    begin
      result := '';
      List := TStringList.Create;
      List.LoadFromFile('List_file.txt'); <<<<< HERE
      try
        for I := 0 to List.Count - 1 do
        begin
          if pos (Key, List.Strings[I]) > 0 then begin
            result:= List.Strings[I];
            break;
          end;
        end;
      finally
        List.Free;
      end;
    end;

     

    What I'm doing wrong? Should I pun it into TOmniMREW lock?

     


  9. procedure TOmniParallelSimpleLoop.Execute(loopBody: TOmniIteratorSimpleSimpleDelegate);
    begin
      InternalExecute(
        procedure (const task: IOmniTask; taskIndex: integer)
        var
          first: integer;
          last : integer;
          step : integer;
        begin
          first := FPartition[taskIndex].LowBound;
          last := FPartition[taskIndex].HighBound;
          step := FStep;
          if step > 0 then begin
            if assigned(FCancelWith) then
              while (first <= last) and (not FCancelWith.IsSignalled) do begin
                loopBody(first);
                Inc(first, step);
              end
            else
              while first <= last do begin
                loopBody(first);  <<<<<<<< HERE error rises, How to find where it is in my code?
                Inc(first, step);
              end
          end
          else begin
            if assigned(FCancelWith) then
              while (first >= last) and (not FCancelWith.IsSignalled) do begin
                loopBody(first);
                Inc(first, step);
              end
            else
              while first >= last do begin
                loopBody(first);
                Inc(first, step);
              end
          end;
        end);
    end; { TOmniParallelSimpleLoop.Execute }

     


  10. Error:

     

      Provider: TELDebugInfoMap
      Location: (00DAF3EF){ANPR_VID.exe     } [0666F3EF] OtlParallel.TOmniParallelSimpleLoop.Execute[2]$ActRec.$0$Body (Line 3440, "OtlParallel.pas" + 16) + $0
        Unit: OtlParallel
        Source: OtlParallel.pas
        Class: TOmniParallelSimpleLoop.Execute[2]$ActRec
        Routine: $0$Body
        Line: 3440

        Routine offset (bytes): 87
        Routine offset (lines): 16
        Line offset (bytes): 0

     

    Why it happens?

×