Skip to content

Commit 334d787

Browse files
committed
fix self-test problems in QtSLiM
1 parent 306399c commit 334d787

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

QtSLiM/QtSLiMWindow.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,14 @@ void QtSLiMWindow::init(void)
395395
// Instantiate the help panel up front so that it responds instantly; slows down our launch, but it seems better to me...
396396
QtSLiMHelpWindow::instance();
397397

398+
// Allocate a RNG temporarily, so it exists when we create the console controller and run self-tests
399+
// This is just for the duration of this init() method; we will tear it down again below
400+
if (!sim_RNG_initialized)
401+
{
402+
_Eidos_InitializeOneRNG(sim_RNG);
403+
sim_RNG_initialized = true;
404+
}
405+
398406
// Create our console window; we want one all the time, so that it keeps live symbols for code completion for us
399407
if (!consoleController)
400408
{
@@ -467,6 +475,13 @@ void QtSLiMWindow::init(void)
467475

468476
beenHere = true;
469477
}
478+
479+
// Tear down the temporary RNG that we created above
480+
if (sim_RNG_initialized)
481+
{
482+
_Eidos_FreeOneRNG(sim_RNG);
483+
sim_RNG_initialized = false;
484+
}
470485
}
471486

472487
void QtSLiMWindow::interpolateVerticalSplitter(void)
@@ -4405,6 +4420,9 @@ void QtSLiMWindow::willExecuteScript(void)
44054420
if (gEidos_RNG_Initialized)
44064421
qDebug() << "eidosConsoleWindowControllerWillExecuteScript: gEidos_rng already set up!";
44074422

4423+
if (!sim_RNG_initialized)
4424+
qDebug() << "sim_RNG is not yet set up!";
4425+
44084426
std::swap(sim_RNG, gEidos_RNG_SINGLE);
44094427
std::swap(sim_RNG_initialized, gEidos_RNG_Initialized);
44104428

eidos/eidos_functions_files.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,18 @@ EidosValue_SP Eidos_ExecuteFunction_writeFile(const std::vector<EidosValue_SP> &
309309
#ifdef SLIMGUI
310310
// we need to provide SLiMgui with information about the file write we just did; this is gross, but it wants to know
311311
// we make a separate buffer for this purpose, with string copies, to donate to Community with &&
312+
EidosContext *context = p_interpreter.Context();
313+
314+
if (context)
312315
{
313-
EidosContext *context = p_interpreter.Context();
314316
std::vector<std::string> slimgui_buffer;
315317

316318
slimgui_buffer.reserve(contents_count);
317319

318320
for (int value_index = 0; value_index < contents_count; ++value_index)
319321
slimgui_buffer.emplace_back(contents_value->StringRefAtIndex_NOCAST(value_index, nullptr));
320322

321-
if (context)
322-
context->FileWriteNotification(file_path, std::move(slimgui_buffer), append);
323-
else
324-
EIDOS_TERMINATION << "ERROR (Eidos_ExecuteFunction_writeFile): (internal error) no Context in Eidos_ExecuteFunction_writeFile()." << EidosTerminate(nullptr);
323+
context->FileWriteNotification(file_path, std::move(slimgui_buffer), append);
325324
}
326325
#endif
327326

@@ -373,8 +372,10 @@ EidosValue_SP Eidos_ExecuteFunction_writeTempFile(const std::vector<EidosValue_S
373372
#ifdef SLIMGUI
374373
// we need to provide SLiMgui with information about the file write we just did; this is gross, but it wants to know
375374
// we make a separate buffer for this purpose, with string copies, to donate to Community with &&
375+
EidosContext *context = p_interpreter.Context();
376+
377+
if (context)
376378
{
377-
EidosContext *context = p_interpreter.Context();
378379
std::string file_path(file_path_cstr);
379380
std::vector<std::string> slimgui_buffer;
380381

@@ -383,10 +384,7 @@ EidosValue_SP Eidos_ExecuteFunction_writeTempFile(const std::vector<EidosValue_S
383384
for (int value_index = 0; value_index < contents_count; ++value_index)
384385
slimgui_buffer.emplace_back(contents_value->StringRefAtIndex_NOCAST(value_index, nullptr));
385386

386-
if (context)
387-
context->FileWriteNotification(file_path, std::move(slimgui_buffer), false);
388-
else
389-
EIDOS_TERMINATION << "ERROR (Eidos_ExecuteFunction_writeTempFile): (internal error) no Context in Eidos_ExecuteFunction_writeTempFile()." << EidosTerminate(nullptr);
387+
context->FileWriteNotification(file_path, std::move(slimgui_buffer), false);
390388
}
391389
#endif
392390

0 commit comments

Comments
 (0)