Trouble with screenshots

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Trouble with screenshots

Post 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?
Attachments
state.love
State Machine demo
(10.79 KiB) Downloaded 120 times
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: Trouble with screenshots

Post by pgimeno »

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

[SOLVED] Re: Trouble with screenshots

Post 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)?
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: Trouble with screenshots

Post 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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Trouble with screenshots

Post 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.
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: Trouble with screenshots

Post 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.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 16 guests