main thread code
Code: Select all
local loadingThread = love.thread.newThread("threadedLoading.lua")
local sendChannel = love.thread.getChannel("sendImage")
local recieveChannel = love.thread.getChannel("recieveImage")
function TextureGet:load()
loadingThread:start()
direcs = {} -- unimportant but holds all the information about where animations and textures are located
local totalImgs = 0
for i, v in ipairs(textureDirecs) do
for j = 1, v.len do
totalImgs = totalImgs + v[j].count
end
end
-- counts all textures needed to be loaded (mainly for making sure the number of textures doesnt get too high
local finishedSendingInfo = false
local loadedImgs = 0
local completionPerc = 0
local direcInd = 1
local itemInd = 1
local countInd = 1
local direcTo = #textureDirecs
local itemTo = textureDirecs[1].len
local countTo = textureDirecs[1][1].count
sendChannel:push({textureDirecs[direcInd][itemInd].direc, countInd, textureDirecs[direcInd][itemInd].type1, textureDirecs[direcInd][itemInd].type2}) -- send info before starting loop
-- while loop doesnt need to be understood, it loops until it recieves the next image then itll send the next info for the next image
--and waits for that, but problem isnt here, thread gets a :push before the loop starts
while not finishedSendingInfo do -- convoluted way of doing a non linear for ( for ( for ())) loop
local rept = recieveChannel:pop()
if rept then
sendChannel:push({textureDirecs[direcInd][itemInd].direc, countInd, textureDirecs[direcInd][itemInd].type1, textureDirecs[direcInd][itemInd].type2})
countInd = countInd + 1
if countInd > countTo then
countInd = 1
itemInd = itemInd + 1
if itemInd > itemTo then
itemInd = 0
direcInd = direcInd + 1
if direcInd > direcTo then
finishedSendingInfo = true
break
end
itemTo = textureDirecs[direcInd].len
end
countTo = textureDirecs[direcInd][itemInd].count
end
end
-- draw screen and push to window
end
end
code with problem in it :
Code: Select all
local recieveChannel = love.thread.getChannel("sendImage")
local sendChannel = love.thread.getChannel("recieveImage")
while true do
local direcInfo = recieveChannel:pop()
-- {'directory', 'number', 'type1', 'type2'}
if type(direcInfo) ~= nil then
print('recieved information') -- when :push is called in main thread this will print
direcInfo[1] = love.image.newImageData(direcInfo[1] .. direcInfo[2] .. '.png') -- code just stops running? when it reaches this line
print('information calculated') -- never prints despite the code above it does
sendChannel:push(direcInfo)
end
end
idk what is happening that could cause this but if there is a fix for this or a different way to load textures in a different thread then i would like to know.