Loading images in a thread
Posted: Wed Oct 19, 2011 6:57 pm
Hey guys, I'm trying to separate my image loading into a separate thread to show a nice loading screen (and perhaps be able to do some background loading at some point, whatevs). However, when I run it on my Mac (OSX Lion) I get a cryptic error:
WTF? I googled the error and it seems to be a mac error related to child processes and OSX Lion, but I tried running the code on my windows computer (Windows 7) and it spits out a completely white image. What the hell am I doing wrong?
main.lua
load.lua
I've attached a .love file if that helps.
Code: Select all
Bus error: 10
![Mad :x](./images/smilies/ms-mad.png)
main.lua
Code: Select all
function love.load()
image = nil
thread = love.thread.newThread("load", "load.lua")
thread:start()
thread:send("path", "image.png")
end
function love.draw()
if image then
love.graphics.draw(image, 0, 0)
end
end
function love.update(dt)
local receive = thread:receive("image")
local error = thread:receive("error")
if receive then
image = receive
elseif error then
print(error)
end
end
Code: Select all
require "love.graphics"
require "love.image"
require "love.filesystem"
local thread = love.thread.getThread()
local path = nil
while path == nil do
path = thread:receive("path")
end
local image = love.graphics.newImage(path)
thread:send("image", image)