Trouble with a seemingly simple snake game(Solved!)

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.
LuaCre
Prole
Posts: 27
Joined: Mon Dec 03, 2018 11:21 am

Trouble with a seemingly simple snake game(Solved!)

Post by LuaCre »

Hi! Thanks for your consideration in helping me and my friends out,

We've got a snake game here, operating in a 25x25 grid with no special obstacles,
the only special things going on is an aspect ratio library called SimpleScale, and the Moonshine library applying the CRT and Scanline shaders.

The game starts paused, you can hit P to un-pause it and will be assigned a direction, WASD and arrow key inputs are supported
The snake moves at the BPM of the soundtrack multiplied by the players score divided by 50, minimum 1
meaning the snake moves at 114 BPM and every 50 points his movement speed doubles.

The snake in question is actually a flute fish, and his snake body is comprised of stone fish.
His food ? People unfortunate enough to be in the water haha

So, the problem in question. Seemingly at random points the game freezes completely, no error codes, just a full crash.
I've tried making this error re-creatable but have failed, only knowing that it will EVENTUALLY occur.

If you hit F1 you will enable lovebird on its default settings, as well as a screen in game showing your texture and script memory usage/ FPS and etcetera. I haven't been able to find anything special happening on my end to cause this problem.

Through search on the forums someone did say it had something to do with the Lua51.dll file and JIT, so I tried using some code that they provided to fix the issue at the bottom of my main scripts load function, but the problem still occurs.

If anyone could narrow down why this problem is occurring that would help out allot :) I hope i'm just doing something madly wrong and it isn't on Love's end, as I really do enjoy this framework.
Snake.love
(6.83 MiB) Downloaded 43 times
Last edited by LuaCre on Sun Nov 20, 2022 12:51 am, edited 1 time in total.
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: Trouble with a seemingly simple snake game

Post by GVovkiv »

First, i see that you found out about "SimpleScale" library for scaling, but may i introduce you to my own https://github.com/Vovkiv/resolution_solution solution to this? (Originally, it was based on this "SimpleScale" which i was not satisfied, so i moved to different solution called "TLfres" which also was not for me, so i made my own. This library is more sane and customizable, so you might prefer it. And yes, this is another shameless plug.)
2nd, I under Linux, with amd rx570 (so, opengl 4.6) and after 5 minutes of play i didn't encounter any crash. What is you system? Are your love is up to day?
In your conf.lua you use t.version = "11.0", so you use love 11.0 or use different version (latest 11.4) and left 11.0?
Also you might want to run love from terminal and see if there something useful will be at the moment of crash?
Glancing at you code, it doesn't seem that there something obviously wrong that might cause crash (unless this is problem with shader, but i don't know anything about shaders so i can't tell anything)
I suspect that it's problem somewhere on your end

Little offtopic, but:
Since you use scaling library, why not allow window resizing? Isn't it main point of scaling?
It's probably not good way to use key "printscreen" since in some os it might be "eaten" by os itself to do screenshot , so better to use something else
LuaCre
Prole
Posts: 27
Joined: Mon Dec 03, 2018 11:21 am

Re: Trouble with a seemingly simple snake game

Post by LuaCre »

I'll check out your library, i dont mind a shameless plug , if its good I'd be glad to use and credit its use in projects :)

Also, F11 is already an additional screenshot button as I foresaw that issue but wanted print screen there for the people who do prefer it.
I completely forgot to just routinely update love and the conf file to reflect the current version but I will absolutely do that right now and compare the results

Furthermore, Im on windows 64-bit, with an AMD Radeon 2700, 32GB of DDR$-3200 MHz Ram and a GTX 1660TI
LuaCre
Prole
Posts: 27
Joined: Mon Dec 03, 2018 11:21 am

Re: Trouble with a seemingly simple snake game

Post by LuaCre »

Upon checking that love was in version 11.4 and that my conf.lua reflected that configuration, I ran the game again which worked with no errors. The crash however, did happen again. This time upon scoring my 70'th point, which has happened before.
LuaCre
Prole
Posts: 27
Joined: Mon Dec 03, 2018 11:21 am

Re: Trouble with a seemingly simple snake game

Post by LuaCre »

GVovkiv wrote: Sat Nov 19, 2022 9:56 pm Little offtopic, but:
Since you use scaling library, why not allow window resizing? Isn't it main point of scaling?
It's probably not good way to use key "printscreen" since in some os it might be "eaten" by os itself to do screenshot , so better to use something else
I resize the window to enact a sort of borderless fullscreen, I dont think that after launch it will have to do so again and any time the window is resized its handled by the game, if for any reason in the future there's opportunity for this to happen more than it does now, Ill enable that boolean

Edit;

The problem seems to happen at random intervals too, on one launch it happened at 10 points, another 65, another 200. The script memory usage never exceed 2KB, texture memory remains a consistent 14MB average.
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: Trouble with a seemingly simple snake game

Post by GVovkiv »

LuaCre wrote: Sat Nov 19, 2022 10:23 pm I resize the window to enact a sort of borderless fullscreen, I dont think that after launch it will have to do so again and any time the window is resized its handled by the game, if for any reason in the future there's opportunity for this to happen more than it does now, Ill enable that boolean
Well, i mean, i, as user of desktop pc, can, in fact, manually make window fullscreen/windowed/borderless fullscreen, so turning off this feature for no reason, by default, seems not really necessary. I might prefer make window floating and resize it for whatever reason to 1280x720. So i don't really understand why disabled it by default.

Welp, after around ~8 mins i bumped into full game freeze, so now i can say that it's indeed code issue. Maybe infinity loop happened somewhere?
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: Trouble with a seemingly simple snake game

Post by GVovkiv »

does disabling luajit helps?
Try jit.off() on top of main lua and check again. If same happens, then it's code issue.
I will try this myself and tell if there difference.
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Trouble with a seemingly simple snake game

Post by MrFariator »

I managed to get the crash around 105 points, after some six minutes of play (some of which was spent dying on purpose). This didn't seem like a jit-related crash, so I took a gander at your code, and found the following:

Code: Select all

--snake.lua, starting from line 137
local occupied = false
repeat 
newfood_position = {math.random(1,25),math.random(1,25)}
for i,v in pairs(snake.all_positions) do 
  if v.x == newfood_position[1] and v.y == newfood_position[2] then 
    occupied = true 
  end
end
until occupied == false  
You're trying to check that the food doesn't spawn inside the player. However, in the event this does happen, you don't seem to have an exit plan, because "occupied" will never become false once it's been turned to true. The game simply gets stuck in an infinite loop, because the variable never becomes false.
Last edited by MrFariator on Sat Nov 19, 2022 11:13 pm, edited 1 time in total.
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: Trouble with a seemingly simple snake game

Post by GVovkiv »

I don't know what exactly trigger this, but i think it has something to do with:

Code: Select all

local newfood_position = {math.random(1,25),math.random(1,25)}
	local occupied = false
			repeat 
			newfood_position = {math.random(1,25),math.random(1,25)}
			for i,v in pairs(snake.all_positions) do 
				if v.x == newfood_position[1] and v.y == newfood_position[2] then 
					occupied = true 
				end
			end
			until occupied == false  
			snake.grid[newfood_position[1]][newfood_position[2]] = 2 
Because it mostly triggers when i try to catch "human"
And in your code human spawns randomly, it might spawn somewhat on top of shake and cause infinity loop?
Last edited by GVovkiv on Sat Nov 19, 2022 11:15 pm, edited 1 time in total.
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: Trouble with a seemingly simple snake game

Post by GVovkiv »

MrFariator wrote: Sat Nov 19, 2022 11:11 pm I managed to get the crash around 105 points, after some six minutes of play (some of which was spent dying on purpose). This didn't seem like a jit-related crash, so I took a gander at your code, and found the following:

Code: Select all

--snake.lua, starting from line 137
local occupied = false
repeat 
newfood_position = {math.random(1,25),math.random(1,25)}
for i,v in pairs(snake.all_positions) do 
  if v.x == newfood_position[1] and v.y == newfood_position[2] then 
    occupied = true 
  end
end
until occupied == false  
You're trying to check that the food doesn't spawn inside the player. However, in the event this does happen, you don't seem to have an exit plan, because "occupied" will never become false once it's been turned to true. The game simply gets stuck in an infinite loop, because the variable never becomes false.
lol, yes, i also was thinking about it.

When occupied become true, what it have to do next?
repeat will continue to go until end of times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 51 guests