Skip to content

Commit

Permalink
Merge pull request #298 from GLVis/najlkin/fix-main-thread
Browse files Browse the repository at this point in the history
[BUG] Fixed init of the main thread
  • Loading branch information
justinlaughlin authored Jul 25, 2024
2 parents fabd4b1 + 03aebea commit 3713964
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions glvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,10 @@ void PlayScript(istream &scr)
script = &scr;
stream_state.keys.clear();

// Make sure the singleton object returned by GetMainThread() is
// initialized from the main thread.
GetMainThread();

std::thread worker_thread
{
[&](StreamState local_state)
Expand Down Expand Up @@ -1490,6 +1494,10 @@ int main (int argc, char *argv[])
// check for saved stream file
if (stream_file != string_none)
{
// Make sure the singleton object returned by GetMainThread() is
// initialized from the main thread.
GetMainThread();

Session stream_session(stream_state.fix_elem_orient,
stream_state.save_coloring);

Expand Down Expand Up @@ -1551,6 +1559,10 @@ int main (int argc, char *argv[])
// server mode, read the mesh and the solution from a socket
if (input == INPUT_SERVER_MODE)
{
// Make sure the singleton object returned by GetMainThread() is
// initialized from the main thread.
GetMainThread();

// Run server in new thread
std::thread serverThread{GLVisServer, portnum, save_stream,
stream_state.fix_elem_orient,
Expand Down Expand Up @@ -1584,6 +1596,11 @@ int main (int argc, char *argv[])
field_type = (use_soln) ? StreamState::FieldType::SCALAR
: StreamState::FieldType::MESH;
}

// Make sure the singleton object returned by GetMainThread() is
// initialized from the main thread.
GetMainThread();

Session single_session(field_type, std::move(stream_state));
single_session.StartSession();

Expand Down
1 change: 1 addition & 0 deletions lib/sdl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef void (*Delegate)();
typedef bool (*IdleDelegate)();

class SdlMainThread;
SdlMainThread& GetMainThread();

class SdlWindow
{
Expand Down

0 comments on commit 3713964

Please sign in to comment.