require call inside a new thread changes the base path

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.
Post Reply
sigmasoldier
Prole
Posts: 2
Joined: Sat Jul 15, 2017 11:09 am

require call inside a new thread changes the base path

Post 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...)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes »

Try requiring love.filesystem first, as it contains the loader that uses the love paths.
sigmasoldier
Prole
Posts: 2
Joined: Sat Jul 15, 2017 11:09 am

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

Post 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!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 58 guests