title: UIGraphicsGetImageFromCurrentImageContext doesn't generate image and returns a nil
body: <p>I have <code>var drawAnimationObjectsByIndex: [Int : DrawAnimationModel] = [:]</code> and the <code>DrawAnimationModel</code> has multiple <code>CAShapeLayer</code> and arrange them in order and adds in a parent layer. The frame index is to keep the <code>DrawAnimationModel</code> in order to generate the images via <code>UIGraphicsGetImageFromCurrentImageContext</code> and put the images in order in <code>AssetWriter</code> to create a movie file (.mov). The process is working till the certain frame index - usually 91/92 out of ~140 and <code>UIGraphicsGetImageFromCurrentImageContext</code> returns nil for all of the rest of calayers. I thought it was memory issue and set <code>autoreleasepool</code> but it seems it's not working. I thought the context might be busy so I reused the context for same dimension and draw the calayers and generate the image but didn't get past the 92.  How do we get the guaranteed image generation by UIGraphicsGetImageFromCurrentImageContext?  Here's the code -</p>
  <pre><code>     autoreleasepool {
              UIGraphicsBeginImageContextWithOptions(settings.size,
              false, UIScreen.main.scale)
                  guard let context = UIGraphicsGetCurrentContext() else {
                      fatalError()
                  }
  
                  var image : UIImage? = nil
                  for index in 0...drawAnimationObjectsByIndex.count  {
                      if let object = drawAnimationObjectsByIndex[index] {
                          object.parent.render(in: context)
                          
                          image = UIGraphicsGetImageFromCurrentImageContext()
                          
                          if let image = image {
                              images.append(image)
                          }
                          else {
                              os_log(&quot;the image is not generated at %d, appending the last image.&quot;, log: self.tag, type: .debug, index)
                              images.append(images.last!)
                          }
                          image = nil
                          drawAnimationObjectsByIndex[index] = nil
                      }
                  }
              UIGraphicsEndImageContext()
          }
  </code></pre>
  <p>Here is the log -</p>
  <pre><code>2021-05-10 05:34:35.705554-0500 apate[5116:2547215] [DrawingRender] is initialized : initialized
  2021-05-10 05:34:35.705585-0500 apate[5116:2547215] [DrawingRender] recordingData.shapesByFrameIndex.count : 173
  2021-05-10 05:34:37.892562-0500 apate[5116:2547215] [DrawingRender] the image is not generated at 92, appending the last image.
  2021-05-10 05:34:37.897744-0500 apate[5116:2547215] [DrawingRender] the image is not generated at 93, appending the last image.
  2021-05-10 05:34:37.901005-0500 apate[5116:2547215] [DrawingRender] the image is not generated at 94, appending the last image.
  </code></pre>
  <p>goes on....</p>