Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCOM: Crash if trying to change non-existing parameter with same name as variable #2115

Open
robbr48 opened this issue Jan 11, 2022 · 4 comments
Assignees
Labels
bug gui:scripting HCOM, Python or Embedded scripting
Milestone

Comments

@robbr48
Copy link
Contributor

robbr48 commented Jan 11, 2022

Describe the bug
Program will crash if user tries to change a model parameter that does not exist, if a variable of the same name exists locally in HCOM.

To Reproduce

  1. Open a new model without a system parameter named "x"
  2. x = 5

  3. chpa x 3

  4. Program will crash

Expected behavior
Show some clever error message.

@robbr48 robbr48 added bug gui:scripting HCOM, Python or Embedded scripting labels Jan 11, 2022
@robbr48 robbr48 added this to the 2.20.0 milestone Jan 11, 2022
@robbr48
Copy link
Contributor Author

robbr48 commented Jan 11, 2022

Seems like it crashes because the code tries to evaluate the parameter name by something called "component index". I have no idea what this code is supposed to do.
https://github.com/Hopsan/hopsan/blob/master/HopsanGUI/HcomHandler.cpp#L2119

//If no parameters found, try if component name can be evaluated by component index instead
if(parameterNames.isEmpty())
{
    evaluateExpression(splitCmd[0].section(".",0,0));
    if(mAnsType == Scalar)
    {
        QString compName = pSystem->getModelObjects().at(mAnsScalar)->getName();
        splitCmd[0].replace(0, splitCmd[0].section(".",0,0).size(), compName);
        getParameters(splitCmd[0], parameterNames);
    }
}

@peterNordin
Copy link
Member

I dont know either, get rid of it.
Probably some ancient stuff, it is not possible for the user to expect at which index in the pointer vector a particular component resides.

@peterNordin
Copy link
Member

A git blame shows you as the author :)

@robbr48
Copy link
Contributor Author

robbr48 commented Jan 14, 2022

Yes, I noticed :) It might have been related to my multicore benchmark models, which were autogenerated by HCOM and had very many components of the same type. But it is useless today, so I will remove it.

@robbr48 robbr48 self-assigned this Jan 14, 2022
@peterNordin peterNordin modified the milestones: 2.20.0, 2.21.0 Jul 11, 2022
@peterNordin peterNordin modified the milestones: 2.21.0, 2.22.0 Jun 10, 2023
@robbr48 robbr48 modified the milestones: 2.22.0, 2.22.1 Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug gui:scripting HCOM, Python or Embedded scripting
Projects
None yet
Development

No branches or pull requests

2 participants