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?
Trouble with screenshots
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Trouble with screenshots
- Attachments
-
- state.love
- State Machine demo
- (10.79 KiB) Downloaded 126 times
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
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.
[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)?
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.
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.
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
Code: Select all
if obj:getFFIPointer() == nil then print("released") end
For other objects
Code: Select all
if tostring(obj):find('NULL') then print("released") end
Re: Trouble with screenshots
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.
Who is online
Users browsing this forum: No registered users and 7 guests