Page 1 of 1

Error Handling: outofmem issue

Posted: Sun Nov 19, 2023 2:47 am
by Karasuro
Environment
Version: Love 11.3
Platform: Raspberry Pi 4 Model B+ (8GB Ram)
System: 32-bit
Kernel version: 6.1
Debian version: 12 (bookworm)

External Requirements
libgphoto2 (external camera control)
lua-periphery (GPIO control)
nativefs (accessing external directories) [included in the archive]

Program Function
Loop a short video while in Idle State.
Receive a signal from a NA-M7RF laser to trigger the capture of an external camera.
Save the JPEG to disk, overwriting any previous JPEGs taken.
Load the new JPEG into the program.
Display the JPEG for 20 seconds.
Return the Idle State.

Error
lib/assetloader.lua 38: Could not decode image with stb_image (outofmem)
That line of code is just: self.cameraImage = love.graphics.newImage("MyFilePath")

assetloader.cameraImage is only used in Draw() by graphics.draw() while in the CameraWait state (See Notes Below)

Notes
Update() and Draw() are written as a basic State Machine.
The program has 4 states: IdleImage, IdleVideo, CameraCapture, and CameraWait
The program should Idle on either IdleImage or IdleVideo (IdleImage is only set if the program can not load the video.)
When the Idle states get a signal from the Laser, it swaps over to CameraCapture where it checks to see if the External Camera saved the image to disk.
If it did not, then it just goes back to Idle. Otherwise it will swap to CameraWait for 20 seconds displaying the new image taken, then it goes back to Idle.

Re: Error Handling: outofmem issue

Posted: Sun Nov 19, 2023 7:31 am
by pgimeno
My first suspicion would be the saved JPEG file, Have you checked if the JPEG loads fine in isolation?

Re: Error Handling: outofmem issue

Posted: Sun Nov 19, 2023 8:06 pm
by Karasuro
Yes. This only occurs after hours of continuous operation which makes me think memory isn't properly getting cleared somewhere.. I just can't pinpoint it.

Re: Error Handling: outofmem issue

Posted: Sun Nov 19, 2023 8:28 pm
by pgimeno
Oh you didn't mention that before did you?

Maybe the issue is that you're not releasing the previous image (Object:release) and there are too many in RAM or VRAM waiting to be garbage-collected?

Re: Error Handling: outofmem issue

Posted: Sun Nov 19, 2023 8:35 pm
by Karasuro
So in assetloader.lua I should just call self.cameraImage:release() before assigning it as a graphics.newImage()? Assuming it's not the first call and self.cameraImage is nil..

Re: Error Handling: outofmem issue

Posted: Sun Nov 19, 2023 9:59 pm
by pgimeno
That's right. See if that solves anything.

Re: Error Handling: outofmem issue

Posted: Sun Nov 19, 2023 10:24 pm
by slime
You may also want to add some validation/logging to your code to make sure the newImage call is happening as infrequently as you expect.