Game crashes when closing

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Anxiety
Prole
Posts: 49
Joined: Sat Apr 02, 2011 9:36 am
Location: Finland

Game crashes when closing

Post by Anxiety »

When i try to close my game, it almost crashes. I think my code has some problems, but maybe you could check it out?

Thanks!

PS: I cant figure out how to reload using a timer, so i would be GLAD if you could fix that for me.
Attachments
TOTAL Shootout.love
(102.63 KiB) Downloaded 97 times
I can't come up with a good signature!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Game crashes when closing

Post by Robin »

I can't see where the problem lies. I can, however, see some other problems:
  • math.random() should only be called once, at the top of the screen.
  • Do not use that sleep function. It stops the whole game, which is not good. You should rewrite it to how you did it with randomisetargetPos.
  • Not so much a problem, but "if shootable == true then" is redundant. Since shootable is boolean, you can just use "if shootable then".
I experience the crash (it hangs when you try to close it) too, but I know not what is the cause.
Help us help you: attach a .love.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Game crashes when closing

Post by Boolsheet »

Create all your fonts at the loading stage. You're wasting a lot of time and memory if you do it on every update. (main.lua line 57)
Make sure you always pass a font object to love.graphics.setFont in the update and draw functions.
Shallow indentations.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Game crashes when closing

Post by kikito »

Let me tell you something about love.graphics.setFont(number)
One-day-It-will-disappear.jpg
One-day-It-will-disappear.jpg (76.84 KiB) Viewed 2680 times
It's just a matter of time.
When I write def I mean function.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Game crashes when closing

Post by BlackBulletIV »

kikito wrote:Let me tell you something about love.graphics.setFont(number)
One-day-It-will-disappear.jpg
It's just a matter of time.
What? Why? Don't tell it's just because it takes a bit for beginners to understand what's really going on.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Game crashes when closing

Post by Boolsheet »

BlackBulletIV wrote:What? Why? Don't tell it's just because it takes a bit for beginners to understand what's really going on.
Well, the function is called setFont and not setAndCreateFont. It delivers more than it should! :P
I told bartbes once that this makes it easier to fall into this trap and he said: "yes, but it's so much more convenient".
Maybe a bigger warning on the wiki might help. :roll:
Shallow indentations.
User avatar
Anxiety
Prole
Posts: 49
Joined: Sat Apr 02, 2011 9:36 am
Location: Finland

Re: Game crashes when closing

Post by Anxiety »

Okay thanks!
I can't come up with a good signature!
User avatar
Anxiety
Prole
Posts: 49
Joined: Sat Apr 02, 2011 9:36 am
Location: Finland

Re: Game crashes when closing

Post by Anxiety »

But wait, Robin? How can i make it loop for only the time of the reload? I know, i suck at it. But im still a beginner :)
I can't come up with a good signature!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Game crashes when closing

Post by kikito »

BlackBulletIV wrote:What? Why? Don't tell it's just because it takes a bit for beginners to understand what's really going on.
Let's see.

Code: Select all

love.graphics.setFont(love.graphics.newFont(2))
-- vs
love.graphics.setFont(2)
Pros:
  • 23 characters less (assuming that you don't assign love.graphics to a local variable and make it shorter). This is the "convenience" bit.
  • Some tutorials use setFont(number), and that would have to be changed
Cons:
  • This is not the first time someone has used it incorrectly. In the forum I've seen 10 or so - I can only wonder how many undetected memory leaking samples are there. This number can only increase, until something changes. Each of the threads is way more tan 23 characters long.
  • Misleading name (setFont when in reality it's createAndSetFont)
  • Resource loading coupled with drawing aspects in one function. We have recently had a discussion about why having love.draw separated from love.update is a good idea. Well, love.graphics.setFont(n) has one feet in love.load and the other one in love.draw. Doesn't that sound strange?
  • Inconsistency. The other graphical "set" functions (i.e. love.graphics.setColor) can be called from inside love.draw; When someone sees a tutorial where love.setFont(n) is used in conjunction with love.graphics.setColor. A very natural step is trying to get multi-colored text by calling love.setColor several times inside love.draw. Well, another logical step is trying to call love.setFont(n) to have two different sizes of fonts. But that is wrong.
But as I said, I think it is a matter of time. Sooner or later, the LÖVE admins will get tired of having to answer the "my app is taking lots of memory & goes too slow" question :) .
When I write def I mean function.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Game crashes when closing

Post by tentus »

Wouldn't a simpler / more convenient solution be to add a check in Love itself to see if the font already exists? We're not talking about something that should consume an inordinate amount of time, from a development or execution perspective, and it won't break old code while fixing the problem that keeps on cropping up.
Kurosuke needs beta testers
Post Reply

Who is online

Users browsing this forum: No registered users and 224 guests