Fix #131. Prevent UI freeze by having a timeout when finding which constraints can be removed to fix jacobian.

This commit is contained in:
phkahler 2020-09-11 15:00:10 -04:00
parent e74185b639
commit 615708440f
3 changed files with 13 additions and 0 deletions

View File

@ -189,6 +189,7 @@ public:
struct { struct {
SolveResult how; SolveResult how;
int dof; int dof;
bool timeout;
List<hConstraint> remove; List<hConstraint> remove;
} solved; } solved;

View File

@ -355,10 +355,17 @@ void System::WriteEquationsExceptFor(hConstraint hc, Group *g) {
} }
void System::FindWhichToRemoveToFixJacobian(Group *g, List<hConstraint> *bad, bool forceDofCheck) { void System::FindWhichToRemoveToFixJacobian(Group *g, List<hConstraint> *bad, bool forceDofCheck) {
auto time = GetMilliseconds();
g->solved.timeout = false;
int a; int a;
for(a = 0; a < 2; a++) { for(a = 0; a < 2; a++) {
for(auto &con : SK.constraint) { for(auto &con : SK.constraint) {
if((GetMilliseconds() - time) > 1500) { // todo: make timeout configurable
g->solved.timeout = true;
return;
}
ConstraintBase *c = &con; ConstraintBase *c = &con;
if(c->group != g->h) continue; if(c->group != g->h) continue;
if((c->type == Constraint::Type::POINTS_COINCIDENT && a == 0) || if((c->type == Constraint::Type::POINTS_COINCIDENT && a == 0) ||

View File

@ -578,6 +578,11 @@ void TextWindow::ShowGroupSolveInfo() {
c->DescriptionString().c_str()); c->DescriptionString().c_str());
} }
if(g->solved.timeout) {
Printf(true, "%FxSome items in list have been ommitted%Fd");
Printf(false, "%Fxbecause the operation timed out.%Fd");
}
Printf(true, "It may be possible to fix the problem "); Printf(true, "It may be possible to fix the problem ");
Printf(false, "by selecting Edit -> Undo."); Printf(false, "by selecting Edit -> Undo.");