Page 1 of 1

require call inside a new thread changes the base path

Posted: Sat Jul 15, 2017 11:15 am
by sigmasoldier
Hello there! I'm running on a huge trouble: I'm trying to make an asynchronous load of all my game's content by moving all the steps into a new thread, but the problem is that the base path inside the new thread is different that the one in the main thread. This means that I cannot share required modules so far.

Example

Code: Select all

-- The main thread
thread = love.thread.newThread('app/load.lua');
thread:start();
In the load.lua

Code: Select all

-- Failing code
local module = require('app.another_module');
-- Bla bla bla
To make it run, I have (in this case for example) to type something like:

Code: Select all

local module = require('dist.app.another_module');
another_module.lua may have other includes for other modules that do work properly if executed in the main thread.

So, the question is, I can avoid this? Or I'll have to make threading more atomic? (Like making a new thread for image loading only and so on...)

Re: require call inside a new thread changes the base path

Posted: Sun Jul 16, 2017 3:04 pm
by bartbes
Try requiring love.filesystem first, as it contains the loader that uses the love paths.

Re: require call inside a new thread changes the base path

Posted: Mon Jul 17, 2017 10:47 am
by sigmasoldier
Works as a charm!!!! Never thought that new threads would mess up the loading system, but as you say I've just noticed that the wiki also says "When a Thread is started, it only loads the love.thread module. Every other module has to be loaded with require. " <- I didn't mind this, my bad.

Anyways, thaks! you saved the day!