Skip to content

Commit

Permalink
improve error-checking and callback policies for frameTick()/show()
Browse files Browse the repository at this point in the history
  • Loading branch information
nmwsharp committed Mar 14, 2024
1 parent 153fe8a commit b7fa095
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/polyscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct ContextEntry {
bool drawDefaultUI;
};
std::vector<ContextEntry> contextStack;
int frameTickStack = 0;

bool redrawNextFrame = true;
bool unshowRequested = false;
Expand Down Expand Up @@ -256,11 +257,24 @@ ImGuiContext* getCurrentContext() { return contextStack.empty() ? nullptr : cont

void frameTick() {

// Make sure we're initialized
// Do some sanity-checking around control flow and use of frameTick() / show()
if (contextStack.size() > 1) {
exception("Do not call frameTick() while show() is already looping the main loop.");
}
if (frameTickStack > 0) {
exception("You called frameTick() while a previous call was in the midst of executing. Do not re-enter frameTick() "
"or call it recursively.");
}
frameTickStack++;

// Make sure we're initialized and visible
checkInitialized();
render::engine->showWindow();

// All-imporant main loop iteration
mainLoopIteration();

frameTickStack--;
}

void requestRedraw() { redrawNextFrame = true; }
Expand Down Expand Up @@ -754,8 +768,7 @@ void buildPickGui() {

void buildUserGuiAndInvokeCallback() {

if (!options::invokeUserCallbackForNestedShow && contextStack.size() > 2) {
// NOTE: this may have funky interactions with manually calling frameTick()
if (!options::invokeUserCallbackForNestedShow && (contextStack.size() + frameTickStack) > 2) {
return;
}

Expand Down

0 comments on commit b7fa095

Please sign in to comment.