## Trouble with screenshots

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
milon
Party member
Posts: 123
Joined: Thu Jan 18, 2018 9:14 pm

### Trouble with screenshots

Hi all,

I was working on a sample state machine / crappy game demo as a followup to this post of mine. I decided to use a screenshot for fun to make some transition effects, and it seems like Love is refusing to make more than 1 screenshot. It either crashes (if I release the old screenshot) or it shows only the original screenshot even after calling for an updated one. See the attached .love file. Any ideas what I'm doing wrong?
Attachments
state.love
State Machine demo
pgimeno
Party member
Posts: 2610
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Trouble with screenshots

What's happening is that you're calling release without clearing the variable. This is especially important in states/fail.lua.
milon
Party member
Posts: 123
Joined: Thu Jan 18, 2018 9:14 pm

### [SOLVED] Re: Trouble with screenshots

pgimeno to the rescue again! Thanks!!

I had no idea objects worked like that. I thought that calling :release() was enough. Is there ever a use case to call :release() and not set the variable to nil (or whatever)?
pgimeno
Party member
Posts: 2610
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Trouble with screenshots

The real problem here was that 'release' does not result in a falsy (i.e. false or nil) value, but you were checking for falsy in some places. Use cases... well, it depends. I imagine that if your code is organized in such a way that you can't immediately set a variable when you release it (e.g. if it's a parameter to a function, and you release it, you can't affect the caller's variable), then you're forced to have the invalid object lingering around.

I don't see any method that allows checking whether an object has been released. That would be interesting to have. If there was one, adding it to your checks would also have solved the problem.
grump
Party member
Posts: 721
Joined: Sat Jul 22, 2017 7:43 pm

### Re: Trouble with screenshots

Code: Select all

if obj:getFFIPointer() == nil then print("released") end
For those objects that provide getFFIPointer at least.

For other objects

Code: Select all

if tostring(obj):find('NULL') then print("released") end
If you really need it. Hacky shit. Best to not need it in the first place.
milon
Party member
Posts: 123
Joined: Thu Jan 18, 2018 9:14 pm

### Re: Trouble with screenshots

pgimeno wrote: Wed Apr 21, 2021 1:56 pm The real problem here was that 'release' does not result in a falsy (i.e. false or nil) value, but you were checking for falsy in some places.
I'd tested doing a print() command with the variable after release, and got NULL every time. I assumed (incorrectly) that would not evaluate to true. Seems like an oversight to me, but now I know.

EDIT: Technically, the print command returned "Image: NULL" which I suppose is slightly different than "NULL".

EDIT: If anyone wants to see the corrected version, I uploaded it to another thread.

### Who is online

Users browsing this forum: Google [Bot] and 37 guests