Page 1 of 1

Trouble with screenshots

Posted: Tue Apr 20, 2021 9:04 pm
by milon
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?

Re: Trouble with screenshots

Posted: Tue Apr 20, 2021 11:34 pm
by pgimeno
What's happening is that you're calling release without clearing the variable. This is especially important in states/fail.lua.

[SOLVED] Re: Trouble with screenshots

Posted: Wed Apr 21, 2021 1:02 pm
by milon
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)?

Re: Trouble with screenshots

Posted: Wed Apr 21, 2021 1:56 pm
by pgimeno
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.

Re: Trouble with screenshots

Posted: Wed Apr 21, 2021 2:26 pm
by grump

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.

Re: Trouble with screenshots

Posted: Wed Apr 21, 2021 4:17 pm
by milon
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.