summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2024-01-01 13:08:39 -0500
committerJonathan Bradley <jcb@pikum.xyz>2024-01-01 13:08:39 -0500
commite91712255f3f06d4bea46cdb0dd3e0150fd156c7 (patch)
tree31d5fc62d317c269e8e962a09cd43ae7025bec89 /editor
parentfd959fcbe543159fb3e8bad990ab712470cbecef (diff)
editor should keep track of forked pid
Diffstat (limited to 'editor')
-rw-r--r--editor/editor.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 008c51f..8c6261e 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -77,7 +77,7 @@ bool shouldOpenSaveSceneDialog = false;
bool shouldOpenNewScene = false;
bool shouldSaveProjectFile = false;
bool shouldRunCurrentScene = false;
-bool subProgramRunning = false;
+__pid_t subProgramPid = -1;
glm::vec3 unproject(glm::vec3 windowCoords) {
double xDevNorm = (2.0f * windowCoords.x) / Extent.width - 1.0f;
@@ -98,11 +98,10 @@ glm::vec3 unproject(glm::vec3 windowCoords) {
void PkeEditor_Tick(double delta) {
if (shouldRunCurrentScene) {
shouldRunCurrentScene = false;
- subProgramRunning = true;
auto *task = Pke_New<std::packaged_task<void()>>();
new (task) std::packaged_task<void()>( [] {
- auto pid = fork();
- if (pid == 0) {
+ subProgramPid = fork();
+ if (subProgramPid == 0) {
int status = -1;
const char *argv[] = {
"pke_runtime",
@@ -113,15 +112,15 @@ void PkeEditor_Tick(double delta) {
};
status = execvp("pke_runtime", const_cast<char **>(argv));
fprintf(stderr, "pke_runtime (child) exited with a status of %i\n", status);
- subProgramRunning = false;
- } else if (pid == -1) {
+ subProgramPid = -1;
+ } else if (subProgramPid == -1) {
fprintf(stdout, "pke_runtime failed to fork\n");
- subProgramRunning = false;
+ subProgramPid = -1;
} else {
int status = 0xCAFEBABE;
- waitpid(pid, &status, 0);
+ waitpid(subProgramPid, &status, 0);
fprintf(stdout, "pke_runtime (parent) exited with a status of %i (0x%08X)\n", status, status);
- subProgramRunning = false;
+ subProgramPid = -1;
}
});
PkeThreads_Enqueue(threadPoolHandle, task);
@@ -561,7 +560,7 @@ void RecordImGuiEditorWrapper() {
ImGui::EndMenu();
}
ImGui::Spacing();
- ImGui::BeginDisabled(subProgramRunning);
+ ImGui::BeginDisabled(subProgramPid != -1);
if (ImGui::Button("▶️")) {
shouldRunCurrentScene = true;
}
@@ -1186,6 +1185,9 @@ void PkeEditor_Disable() {
void PkeEditor_Teardown() {
PkeEditor_Disable();
+ if (subProgramPid != -1) {
+ kill(subProgramPid, SIGINT);
+ }
PkeThreads_Teardown(threadPoolHandle);
entityInstancesToCreate.~DynArray();
}