Crash of engine (CoE)

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.
User avatar
TC1061
Prole
Posts: 32
Joined: Sat Oct 14, 2017 3:50 pm

Re: Crash of engine (CoE)

Post by TC1061 »

zorg wrote: Sat Oct 14, 2017 6:45 pm i know it's possible in threads (except graphics stuff) but i'm not sure if it is on the main thread, to be honest
You can use graphics stuff in threads, but it's recommended to use it in one (any!) only thread.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Crash of engine (CoE)

Post by erasio »

TC1061 wrote: Wed Oct 18, 2017 6:57 am You can use graphics stuff in threads, but it's recommended to use it in one (any!) only thread.
In theory if you write your own engine. You are right.

In love2d. You are wrong. From the thread docs:
The love.graphics and love.window modules have several restrictions and therefore can only be used in the main thread.
User avatar
TC1061
Prole
Posts: 32
Joined: Sat Oct 14, 2017 3:50 pm

Re: Crash of engine (CoE)

Post by TC1061 »

erasio wrote: Wed Oct 18, 2017 11:24 am
TC1061 wrote: Wed Oct 18, 2017 6:57 am You can use graphics stuff in threads, but it's recommended to use it in one (any!) only thread.
In theory if you write your own engine. You are right.

In love2d. You are wrong. From the thread docs:
The love.graphics and love.window modules have several restrictions and therefore can only be used in the main thread.
But, why this code works fine in love2d 0.10.2?

Code: Select all

if love.window then
	love.window.close()
end
if not love.thread then
	require("love.thread")
end
love.event=nil
function love.threaderror(_,err) error(err,0) end
thread=love.thread.newThread[=[
require("love.window")
require("love.graphics")
require("love.event")
local g=love.graphics
local w=love.window
w.setMode(800,600)
while true do
for n, a, b, c, d, e, f in love.event.poll() do
	if n == "quit" then
		return
	end	
end
	g.points(math.random(1,g.getWidth()),math.random(1,g.getHeight()))
	g.present()
end
-- Mua-ha-ha-ha-ha
]=]
thread:start()
while true do end -- So, it really works :)
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Crash of engine (CoE)

Post by erasio »

TC1061 wrote: Wed Oct 18, 2017 2:22 pm But, why this code works fine in love2d 0.10.2?
I'd assume because the warning doesn't mean it's not working at all but that there are serious issues that can arise beyond regular concurrency issues.

Like some (important) functions not being available or undocumented and unexpected behavior.

In general. Ignoring good documentation without knowing why it's been written this way is not a smart move.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Crash of engine (CoE)

Post by bartbes »

As far as I know love.graphics can be used from any thread (there isn't really anything special about the main thread after all), but only as long as all things related to windowing are also done from that thread. That also includes event handling like in TC1061's example.

I don't think there's a real advantage though, because you end up with a situation where another thread is treated much like the main thread is normally.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Crash of engine (CoE)

Post by slime »

bartbes wrote: Wed Oct 18, 2017 6:25 pm As far as I know love.graphics can be used from any thread (there isn't really anything special about the main thread after all), but only as long as all things related to windowing are also done from that thread. That also includes event handling like in TC1061's example.
On some operating systems (macOS and iOS, for example) this isn't possible and will either crash or cause corruptions at runtime.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 57 guests