[SOLVED] Strange bitmap bug lazarus / 31-LCL ---------------------------------------------------------------------- MiniApp · 2017-03-05 15:10 Hello, I'm trying to create a program who need lot of pictures (I load more than 1 042 PNG's at start). I don't know why but after a massive load I have a access violation after a random time. I think this can be a LCL bug because the bug is when I move my mouse in my main form. Stranger I have created and show a form before my massive load, and he work perfectly ! My function to load bitmaps is Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function LoadPicture(const FileName:TFilename):TBitmap;begin  Result := TBitmap.Create;  LoadPicture(FileName,Result);end;procedure LoadPicture(const FileName:TFilename;const Bitmap:TBitmap);begin//  LoadPicturePicture := TPicture.Create;  InternalLogger.Info('Begin LoadPicture from "%s"',[FileName]);  try    LoadPicturePicture.LoadFromFile(FileName);    Bitmap.SetSize(LoadPicturePicture.Width,LoadPicturePicture.Height);  Bitmap.Canvas.Draw(0,0,LoadPicturePicture.Graphic);  except    on E:Exception do      begin        InternalLogger.Error('End LoadPicture fail ! [%s] %s',[E.ClassName,E.Message]);        raise;      end;  end;  InternalLogger.Info('End LoadPicture');//  LoadPicturePicture.Free;end; I load pictures in a FormCreate and I store them into a array. I have two times this bug and this make me  . Have you a answer ? ps:Sorry if my english is bad... ---------------------------------------------------------------------- Thaddy · 2017-03-05 15:24 How big are these pictures? I suspect this is caused by out-of-memory. In that case the exception can not be handled in your code. You can test this by making a small change to your code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   except  // add this first. Only works if first.    on E:EOutOfMemory do       raise;  // This gets handled by a pre-allocated Dialog    on E:Exception do    begin              // this won't work for an EOutOfMemory exception because it needs new memory       InternalLogger.Error('End LoadPicture fail ! [%s] %s',[E.ClassName,E.Message]);       raise;    end;  end;   I have added a screenshot. It is usually a bad  idea to try to store 1042 png's in memory at the same time..... ---------------------------------------------------------------------- MiniApp · 2017-03-06 17:30 Thank you for your reply, but it's not a memory overload. Pictures makes 128x128 (I have calculated 48MB for all pixels of pictures). And I have the same problem with 100 pictures of 64x64. I will try to use the no OS handle Bitmap. ---------------------------------------------------------------------- MiniApp · 2017-03-06 19:50 This work ! But look my func...  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function LoadLCLPicture(const FileName:TFilename):TLazIntfImage;var  Bmp:TBitmap;begin  Bmp := LoadPicture(FileName);  Result := Bmp.CreateIntfImage;  Bmp.Free;end;I don't know how is possible . My project is very strangly bugged (A other subproc create a undefined number of TImage, but he work only one time ! ). For the  memory consumption, I'm in 50MB after start, this should not be problematic on today computer. Note:If anyone have more information on this strange bug I listen him ---------------------------------------------------------------------- Thaddy · 2017-03-06 20:25 Yes. CreateIntfImage makes it either an interfaced image instance or it makes a copy as an interface. An interface is refcounted and free'd when out of scope. It is either a copy or the refcount for bmp.free is not 0. (So it can be a fake free). You have to find out what CreateIntfImage exactly does, though, in the sourcecode.... Nice task for you...!! Mixing interface instantiation with class instantiation on the same class and in one program, though, is not a brilliant idea and should be avoided to keep it clean. Strictly either / or.