You can use graphics stuff in threads, but it's recommended to use it in one (any!) only thread.
Crash of engine (CoE)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Crash of engine (CoE)
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.
Re: Crash of engine (CoE)
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 :)
Re: Crash of engine (CoE)
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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Crash of engine (CoE)
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.
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.
- slime
- Solid Snayke
- Posts: 3131
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Crash of engine (CoE)
On some operating systems (macOS and iOS, for example) this isn't possible and will either crash or cause corruptions at runtime.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.
Who is online
Users browsing this forum: Google [Bot] and 57 guests