-
Notifications
You must be signed in to change notification settings - Fork 232
Closed
Description
Using Polyscope C++, I'm facing an error using ScalarQuantity under a custom GUI build.
To replicate the error :
- polyscope::options::buildGui=false,
- only polyscope::buildStructureGui() in the callback() loop,
- create a point cloud, add a ScalarQuantity,
- remove the point cloud when the scalarQuantity isn't collapsed.
It creates the following error :
terminate called after throwing an instance of 'std::runtime_error'
what(): [polyscope] [EXCEPTION] OpenGl error occurred. Text: Invalid operation
It seems that using the classic GUI, the quantities collapse when removing the point cloud.
The same behavior occurs for VectorQuantity : it seems to collapse before removing the point cloud, and no problem here, even in custom GUI.
Using the same behavior in a two-step way inside the partial GUI fixes the issue (collapsing the "Structures" window before removing the point cloud containing the quantities).
Code to replicate the error
#include <imgui_internal.h>
#include <polyscope/polyscope.h>
#include <polyscope/point_cloud.h>
std::string name = "randomPC";
std::vector<std::array<float, 3>> randomPoints;
std::vector<float> randomQuantities;
std::vector<std::array<float, 3>> randomVectors;
bool changed = false;
bool needCollapse = false;
void randomPC() {
name = "randomPC_" + std::to_string(rand());
randomPoints.clear();
randomQuantities.clear();
randomVectors.clear();
for (int i = 0; i < 100; i++) {
randomPoints.push_back({static_cast<float>(rand()) / RAND_MAX, static_cast<float>(rand()) / RAND_MAX, static_cast<float>(rand()) / RAND_MAX});
randomQuantities.push_back(static_cast<float>(rand()) / RAND_MAX);
randomVectors.push_back({static_cast<float>(rand()) / RAND_MAX, static_cast<float>(rand()) / RAND_MAX, static_cast<float>(rand()) / RAND_MAX});
}
}
void updatePC() {
if ( polyscope::hasPointCloud(name) ) {
polyscope::removePointCloud(name, false);
// return; // => To specifically show the error when removing the point cloud
}
randomPC();
auto pc = polyscope::registerPointCloud(name, randomPoints);
std::string randomQuantitiesName = "randomQuantities";
randomQuantitiesName += "_" + std::to_string(rand());
pc->addScalarQuantity(randomQuantitiesName, randomQuantities); // => Bug Here
pc->addVectorQuantity("randomVectors", randomVectors); // => Working Fine
}
void callback() {
if ( ! polyscope::options::buildGui ){
ImGuiWindow *window = ImGui::FindWindowByName( "Structures" );
if (changed && window) {
window->Collapsed = true;
needCollapse = false;
}
polyscope::buildStructureGui();
}
ImGui::Begin("RandomPoints", nullptr);
if (ImGui::Button("Without Collapsing")) {
changed = true;
}
if (ImGui::Button("With Collapsing")) {
changed = true;
needCollapse = true;
}
if ( changed && not needCollapse ) {
changed = false;
updatePC();
}
ImGui::End();
}
int main(int argc, char **argv) {
polyscope::options::autocenterStructures = true;
polyscope::options::buildGui = false;
polyscope::init();
polyscope::state::userCallback = callback;
polyscope::show();
return EXIT_SUCCESS;
}Metadata
Metadata
Assignees
Labels
No labels