I’ve just implemented threading for a part of my project, and–being a little uncertain in matters of threading–I would like to check whether I’m incurring any potential issues, if I may.
What I’m doing is this: When an area in my project is instructed to respawn its characters, a thread is generated. Into this thread are passed a number of objects, most of which are simply sources of data.
However, a few are modified, specifically in having various objects added to their scene-graphs, and to lists or dictionaries that they control. Rooms may have characters (e.g. enemies) added, and maps may have icons added.
Is it safe to so add nodes to the scene-graph from a thread?
Further, I’m currently using the basic “loadModel”/“Actor” method/constructor, just called from within the thread–is that okay, or should I make a point of switching to the asynchronous versions…?
On a similar note, is it safe to call from a thread a method of an object that was not created in that thread? That is, something like this:
class MyThread(threading.Thread): def __init__(self, someExternalObj): self.someExternalObj = someExternalObj def run(self): self.someExternalObj.someMethod() #Elsewhere, in another class... aNewThread = MyThread(self.someLocalObject) aNewThread.start()
And finally, if I do so call such a method, will logic within that method–and in particular model-loading calls–be threaded, or will they happen in the main thread…?
 I have seen this post, which mentions a potential problem with “… having geometry in the scene graph while it is simultaneously being modified in a child thread”. However, I’m currently assuming that this only refers to geometry that has not yet been fully made/loaded, rather than geometry that has been loaded the traditional way, just in a thread.