I am probably doing something silly here but should the following code work? Depending on the bitmap's dimensions the loop crashes after a consistent number of iterations. The larger the dimensions, the fewer the iterations before it crashes. (With 1280x720 it crashes after 394 iterations on an iPhone SE.) I assume there is some memory issue at play. Nothing is written to the log when it crashes, the app simply closes. I have never seen it crash on the simulator but that's perhaps due to the amount of memory available?
I have included a couple of comments in the code just to show that the real code is doing something more interesting than writing a black bitmap on top of another 1000 times!
B4X:
bc1.Initialize(1280,720)
bc1.DrawRect(bc1.TargetRect,Colors.Black,True,1)
Dim bmp As B4XBitmap=bc1.Bitmap
bc2.Initialize(1280,720)
For i=1 To 1000
'generate a new bmp
bc2.DrawBitmap(bmp, bc2.TargetRect, True)
'write bc2.bitmap
Log(i)
Next
I thought you meant that the "generate a new bmp" code was not releasing memory. I still don't understand why having the one bitmap generated before the loop starts and then copying it to a BitmapCreator (1000 times) should generate any memory issues.
However, I can confirm that the following works
B4X:
for i=1 to 1000
bc2.DrawBitmapCreator(bc1, bc1.TargetRect,0,0, True)
log(i)
next
The reason I didn't take that route initially was, once I get to the real code, I would have to convert the bitmap, from "getNextBitmap", to a BitmapCreator and hence run into the memory issues again. Something like:
B4X:
For i=1 To 1000
bmp=getNextBitmap
bmpRect.Initialize(0,0,bmp.Width,bmp.Height)
bc1.DrawBitmap(bmp, bmpRect, True)
bc2.DrawBitmapCreator(bc1, bc1.TargetRect,0,0, True)
Log(i)
Next
I guess what I need to do is instead of having a "getNextBitmap", I create a "getNextBitmapCreator" and then its output can be used directly by DrawBitmapcreator.