Game Development Community

Debugging TGB project with Threads in Torsion

by Maxim Kosheev · in Technical Issues · 11/26/2008 (9:56 am) · 3 replies

Hello community!
For my project game in TGB, it was necessary to create an additional programming thread. I have successfully coped with this problem:). But my problem began during debug my project in Torsion. Once the thread created and started to work I have been (in a loop while) interview his state with function Thread:: isAlive.
The loop ends when when the thread ends (ie isAlive returns false). At some point in time the loop stops (it stops rather than ends). Application respectively stops. If the project does not run out of Torsion, then everything works fine.
It must be said that within that loop, I am printing a text string using "echo".
If you do not use this function, then everything works fine.
The loop code:
While (!% IsLoaded)
(
% IsLoaded = $ dictionary.isLoaded ();
Echo ( "Loading status",% isLoaded);
)

About the author

Recent Threads

  • TGB to iTGB
  • Multiple texture

  • #1
    11/27/2008 (2:30 am)
    I'm not entirely sure i understand what your doing... are you saying that the script is running in a separate thread?

    TorqueScript is *not* thread safe... if your creating a thread in C++ and trying to do Con::exec() calls from it you're gonna to have random crashes of your game.
    #2
    11/28/2008 (7:17 am)
    Ok!
    I had created new thread in C++. This thread loading words dictionary. I have function in C++ (isLoaded) returning true when thread is finished (Thread::isAlive return false).

    In script i have a loop:
    While (!%IsLoaded)
    (
    %IsLoaded = $ dictionary.isLoaded ();
    Echo ( "Loading status",% isLoaded);
    )

    This loop stops.

    If loop look like this:
    While (!%IsLoaded)
    (
    %IsLoaded = $ dictionary.isLoaded ();
    )
    it's work well
    #3
    11/29/2008 (8:29 am)
    Wouldn't an alternative be to have you main script code invoke a console method to loadDictionary. Then have this method start off the threaded load code. When the threaded code has finished, resynchronise with the main tge thread and have that main thread do the script onDictionaryLoaded callback.

    That way you'd get the asynchronous loading, but keep all calls to/from script in the same main tge thread. You'd also no longer need any kind of while spinning.