Canvas sometimes renders empty

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
Bananicorn
Prole
Posts: 37
Joined: Thu Apr 12, 2018 9:59 am

Canvas sometimes renders empty

Post by Bananicorn »

Okay, so I have a simple parallax background, which consists of 3 layers, and is updated every 4 frames.
So far so good, but when my system is under load, or I load a bigger chunk of the map, so the framerate drops, it sometimes simply doesn't draw the background for a frame or two, which is, well... bad.

The problem with lags when a map-part is buffered is a whole other story, and the next thing I'll fix, but I've at least got some idea as to what I need to do there.

I thought it might be a problem with my GPU not catching up with rendering the background on time, since that's the only part which *might* run serially, like the rest of the code, since it's performed by the GPU...

It works fine if I directly draw the different layers to the screen (each of them already is a canvas)

This is the function in question:

Code: Select all

function update_parallax_background ()
	love.graphics.push()
	love.graphics.setCanvas(assets.bg_canvas)
	assets.skybox:draw(0, 0)
	local curr_tile_size = map_manager.tile_size * camera.scale_factor --is also the window width
	local offset_x = (((camera.offset_x / map_manager.tile_size) * -25) % map_manager.tile_size) * camera.scale_factor

	local inner_offset_x = ((curr_tile_size - offset_x) / camera.scale_factor) % curr_tile_size
	assets.background.quad:setViewport(0, 0, inner_offset_x, map_manager.tile_size)
	assets.background:draw(offset_x, 0)
	assets.background.quad:setViewport(inner_offset_x, 0, map_manager.tile_size - inner_offset_x, map_manager.tile_size)
	assets.background:draw(0, 0)

	offset_x = (((camera.offset_x / map_manager.tile_size) * -50) % map_manager.tile_size) * camera.scale_factor
	inner_offset_x = ((curr_tile_size - offset_x) / camera.scale_factor) % curr_tile_size
	assets.background2.quad:setViewport(0, 0, inner_offset_x, curr_tile_size)
	assets.background2:draw(offset_x, 0)
	assets.background2.quad:setViewport(inner_offset_x, 0, map_manager.tile_size - inner_offset_x, curr_tile_size)
	assets.background2:draw(0, 0)
	love.graphics.setCanvas()
	love.graphics.pop()
end
Which is called from here:

Code: Select all

function render ()
	love.graphics.setBlendMode("alpha")
	love.graphics.draw(assets.bg_canvas, 0, 0)
	love.graphics.push()
	love.graphics.translate(-camera.offset_x * camera.scale_factor, -camera.offset_y * camera.scale_factor)
	draw_map()
	draw_players()
	draw_dynamic_objects()
	love.graphics.pop()

	love.graphics.setColor(1, 1, 1, 1)
	love.graphics.draw(ui.upper_canvas, 0, 0)
	if #ui.middle_texts > 0 then
		love.graphics.draw(ui.middle_canvas, 0, ui.height)
	end
	if #ui.bottom_texts > 0 then
		love.graphics.draw(ui.bottom_canvas, 0, ui.height * 2)
	elseif ui.keyboard_hint_duration > 0 then
		local keyboard_width, keyboard_height = assets.keyboard.canvas:getDimensions()
		assets.keyboard:draw(ui.width / 2 - keyboard_width / 2, ui.height * 2 + H_UNIT_UI * 5)
	end
	if ui.frame_counter % ui.parallax_refresh_rate == 0 then
		update_parallax_background()
	end
	if ui.fade_opacity > 0 then
		love.graphics.setColor(0, 0, 0, ui.fade_opacity)
		love.graphics.rectangle("fill",0,0,love.graphics.getWidth(), love.graphics.getHeight())
	end
	love.graphics.print(love.timer.getFPS(), 10, 10)
	ui.frame_counter = ui.frame_counter + 1
end
I appreciate any kind of theory as to what I might be doing wrong, since I'm completely stumped by this...
Attachments
the_sparrow_effect.love
(1.7 MiB) Downloaded 48 times
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Canvas sometimes renders empty

Post by pgimeno »

You've left the colour changed on entry to render().

I've added print(love.graphics.getColor()); love.timer.sleep(0.5) right before the background drawing call, and this is the output:

Code: Select all

0.86274510622025	0.86274510622025	0.86274510622025	1
1	1	1	1
1	1	1	1
1	1	1	1
0	0	0	0
1	1	1	1
1	1	1	1
1	1	1	1
1	1	1	1
1	1	1	1
1	1	1	1
1	1	1	1
1	1	1	1
1	1	1	1
1	1	1	1
1	1	1	1
1	1	1	1
0.66666668653488	0.63529413938522	0.60784316062927	1
1	1	1	1
1	1	1	1
...
Bananicorn
Prole
Posts: 37
Joined: Thu Apr 12, 2018 9:59 am

Re: Canvas sometimes renders empty

Post by Bananicorn »

I can't believe I forgot to reset the color!
Well, actually I can, thank you very much! :)

Btw, is there anywhere I can buy you a coffe or something? Thank you SO much for taking your time :)
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Canvas sometimes renders empty

Post by pgimeno »

You're very welcome :) I enjoy helping when people make it easy, and you provided your project, which is the best way to be able to reproduce the problem. People often have a concept of where the problem is, that differs from where it actually is, and don't provide enough data to diagnose the problem.

I love how your project is looking so far, by the way. The animation is great. I played with it for a while, it's fun, so consider that as a payment ;)
Bananicorn
Prole
Posts: 37
Joined: Thu Apr 12, 2018 9:59 am

Re: Canvas sometimes renders empty

Post by Bananicorn »

pgimeno wrote: Sat Oct 27, 2018 5:45 pm You're very welcome :) I enjoy helping when people make it easy, and you provided your project, which is the best way to be able to reproduce the problem. People often have a concept of where the problem is, that differs from where it actually is, and don't provide enough data to diagnose the problem.

I love how your project is looking so far, by the way. The animation is great. I played with it for a while, it's fun, so consider that as a payment ;)
Aw, thanks! :D
You're one of the few people who have seen it in that state, I hope to polish this a lot more (and actually add content, heh).
You're going into the credits if you don't mind :)
I'm not sure if you want that though, so I'm waiting until you approve^^
I'll have some more motivation to get this finished then, too ;)
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Canvas sometimes renders empty

Post by pgimeno »

Bananicorn wrote: Thu Nov 08, 2018 11:17 amAw, thanks! :D
You're one of the few people who have seen it in that state, I hope to polish this a lot more (and actually add content, heh).
You're going into the credits if you don't mind :)
I'm not sure if you want that though, so I'm waiting until you approve^^
I'll have some more motivation to get this finished then, too ;)
Yes I appreciate that :nyu: Thank you!
Post Reply

Who is online

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