Threading and setGeom

Return to Scripting Issues

Threading and setGeom

Postby EdBighead » Thu Mar 01, 2012 1:03 pm

In my game, I'm dynamically altering geometry by using node.setGeom(geomId, geom). Creating the geometries can take a while, so I'm trying to create them in a thread, and then later change the geometry of the node to the new geom. Unfortunately, the game is freezing when I call setGeom with a geom that has been created in a thread (or a separate task chain).

What I'm doing is:
Code: Select all
thread.start_new_thread(ThreadedUpdate, (self, self.blocks, self.blockTexture, self.x, self.y, self.z))


Code: Select all
def ThreadedUpdate(self, blocks, blockTexture, x, y, z):
    ...
    self.threadQueue.put_nowait(geom)


Then later
Code: Select all
geom = self.threadQueue.get_nowait()
node.setGeom(geomId, geom)


I can print out the geom after the thread creates it, but the game freezes without displaying errors as soon as I call setGeom with the new geom. If I do everything the same, but call ThreadUpdate without giving it its own thread, it works successfully.

I noticed the warning in the API, but I'm not quite sure what it means:

Description: Replaces the nth Geom of the node with a new pointer. There must already be a Geom in this slot.
Note that if this method is called in a downstream stage (for instance, during cull or draw), then it will propagate the new list of Geoms upstream all the way to pipeline stage 0, which may step on changes that were made independently in pipeline stage 0. Use with caution.
EdBighead
 
Posts: 109
Joined: Tue Jan 18, 2011 12:14 pm
Location: U.S.

Postby drwr » Tue Apr 24, 2012 12:23 pm

That warning isn't relevant unless you are using pipelining (e.g. with "threading-model Cull/Draw" in your Config.prc). Even though it's not usually a significant problem.

One thing that *is* a problem is having geometry in the scene graph while it is simultaneously being modified in a child thread. This can cause deadlocks or graphics failures when the render thread tries to draw incomplete data. When you're creating geometry in a child thread, it's important to ensure that (a) you don't add it to the scene graph until it is fully created, and (b) once it is added to the scene graph, you no longer modify that particular object.

Other than these ideas, I don't know what's causing your lockup. This should work in general; and I do things like this from time to time successfully.

David
drwr
 
Posts: 11425
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA

Postby EdBighead » Tue Apr 24, 2012 8:30 pm

Thanks for the reply. I'll look into it more and see what I can come up with.
EdBighead
 
Posts: 109
Joined: Tue Jan 18, 2011 12:14 pm
Location: U.S.


Return to Scripting Issues

Who is online

Users browsing this forum: No registered users and 2 guests