<commit_before>#include "RenderManager.h"
#include <QMutexLocker>
#include "Core.h"

RenderManager::RenderManager()
{
  m_Running = false;
  m_Thread = NULL;
}

RenderManager::~RenderManager()
{
}

void RenderManager::Init(int proxyRenderer, QString replayHost, QString logfile, float *progress)
{
  if(m_Running)
    return;

  m_ProxyRenderer = proxyRenderer;
  m_ReplayHost = replayHost;
  m_Logfile = logfile;
  m_Progress = progress;

  *progress = 0.0f;

  m_Thread = new LambdaThread([this]() { run(); });
  m_Thread->start(QThread::HighestPriority);

  while(m_Thread->isRunning() && !m_Running)
  {
  }
}

bool RenderManager::IsRunning()
{
  return m_Thread->isRunning() && m_Running;
}

void RenderManager::AsyncInvoke(RenderManager::InvokeMethod m)
{
  InvokeHandle *cmd = new InvokeHandle(m);
  cmd->selfdelete = true;

  PushInvoke(cmd);
}

void RenderManager::BlockInvoke(RenderManager::InvokeMethod m)
{
  InvokeHandle *cmd = new InvokeHandle(m);

  PushInvoke(cmd);

  while(!cmd->processed)
  {
  }
}

void RenderManager::CloseThread()
{
  m_Running = false;

  m_RenderCondition.wakeAll();

  // wait for the thread to close and clean up
  while(m_Thread->isRunning())
  {
  }

  m_Thread->deleteLater();
}

void RenderManager::PushInvoke(RenderManager::InvokeHandle *cmd)
{
  if(m_Thread == NULL || !m_Thread->isRunning() || !m_Running)
  {
    cmd->processed = true;
    if(cmd->selfdelete)
      delete cmd;
    return;
  }

  m_RenderLock.lock();
  m_RenderQueue.push_back(cmd);
  m_RenderCondition.wakeAll();<commit_msg>Don't try to close & delete a NULL thread<commit_after>#include "RenderManager.h"
#include <QMutexLocker>
#include "Core.h"

RenderManager::RenderManager()
{
  m_Running = false;
  m_Thread = NULL;
}

RenderManager::~RenderManager()
{
}

void RenderManager::Init(int proxyRenderer, QString replayHost, QString logfile, float *progress)
{
  if(m_Running)
    return;

  m_ProxyRenderer = proxyRenderer;
  m_ReplayHost = replayHost;
  m_Logfile = logfile;
  m_Progress = progress;

  *progress = 0.0f;

  m_Thread = new LambdaThread([this]() { run(); });
  m_Thread->start(QThread::HighestPriority);

  while(m_Thread->isRunning() && !m_Running)
  {
  }
}

bool RenderManager::IsRunning()
{
  return m_Thread->isRunning() && m_Running;
}

void RenderManager::AsyncInvoke(RenderManager::InvokeMethod m)
{
  InvokeHandle *cmd = new InvokeHandle(m);
  cmd->selfdelete = true;

  PushInvoke(cmd);
}

void RenderManager::BlockInvoke(RenderManager::InvokeMethod m)
{
  InvokeHandle *cmd = new InvokeHandle(m);

  PushInvoke(cmd);

  while(!cmd->processed)
  {
  }
}

void RenderManager::CloseThread()
{
  m_Running = false;

  m_RenderCondition.wakeAll();

  if(m_Thread == NULL)
    return;

  // wait for the thread to close and clean up
  while(m_Thread->isRunning())
  {
  }

  m_Thread->deleteLater();

  m_Thread = NULL;
}

void RenderManager::PushInvoke(RenderManager::InvokeHandle *cmd)
{
  if(m_Thread == NULL || !m_Thread->isRunning() || !m_Running)
  {
    cmd->processed = true;
    if(cmd->selfdelete)
      delete cmd;
    return;
  }

  m_RenderLock.lock();
  m_RenderQueue.push_back(cmd);
  m_RenderCondition.wakeAll();
{'fraction_non_alphanumeric': 0.1391167192429022, 'fraction_numerical': 0.0012618296529968455, 'mean_word_length': 4.622340425531915, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '908235', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1105, 'n_words': 203}