Skip to content

Commit

Permalink
add more frameTick() tests and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nmwsharp committed Dec 23, 2023
1 parent f453642 commit 171c734
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/polyscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ ImGuiContext* getCurrentContext() { return contextStack.empty() ? nullptr : cont
void frameTick() {

// Make sure we're initialized
if (!state::initialized) {
exception("must initialize Polyscope with polyscope::init() before calling polyscope::frameTick().");
}

checkInitialized();
render::engine->showWindow();

mainLoopIteration();
Expand Down Expand Up @@ -817,7 +814,7 @@ void draw(bool withUI, bool withContextCallback) {
}

// Execute the context callback, if there is one.
// This callback is Polyscope implementation detail, which is distinct from the userCallback (which gets called above)
// This callback is a Polyscope implementation detail, which is distinct from the userCallback (which gets called above)
if (withContextCallback && contextStack.back().callback) {
(contextStack.back().callback)();
}
Expand Down
23 changes: 23 additions & 0 deletions test/src/basics_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ TEST_F(PolyscopeTest, FrameTick) {
}
}

TEST_F(PolyscopeTest, FrameTickWithImgui) {

auto showCallback = [&]() { ImGui::Button("do something"); };
polyscope::state::userCallback = showCallback;

for (int i = 0; i < 5; i++) {
polyscope::frameTick();
}

polyscope::state::userCallback = nullptr;
}

// We should be able to nest calls to show() via the callback. ImGUI causes headaches here
TEST_F(PolyscopeTest, NestedShow) {

Expand All @@ -43,6 +55,17 @@ TEST_F(PolyscopeTest, NestedShow) {
polyscope::state::userCallback = nullptr;
}

TEST_F(PolyscopeTest, NestedShowWithFrameTick) {

auto showCallback = [&]() { polyscope::show(3); };
polyscope::state::userCallback = showCallback;

for (int i = 0; i < 3; i++) {
polyscope::frameTick();
}

polyscope::state::userCallback = nullptr;
}

// Make sure that creating an empty buffer does not throw errors
TEST_F(PolyscopeTest, EmptyBuffer) {
Expand Down

0 comments on commit 171c734

Please sign in to comment.