Bug - Exception: Attempted to divide by zero

I’m calling GenerateJSONTemplate using markup and it is resulting in “Error occurred during generation process. Please contact support. Exception message: Attempted to divide by zero.”

I’ve attached my markup JSON file. It seems to have something to do with the answers_string value for the last question in the Markup.json file…but it is unclear what the problem is.

// code
var omrLicense = new License();
omrLicense.SetLicense(new FileStream(@"D:\dev\AsposeOmrTesting\AsposeOmrTesting\Aspose.OMR.Product.Family.lic", FileMode.Open));

var engine = new OmrEngine();
GenerationResult res = engine.GenerateJSONTemplate(@"D:\dev\AsposeOmrTesting\AsposeOmrTesting\DebugFiles\Markup.json");
// res.ErrorMessage at this point is:  "Error occurred during generation process. Please contact support. Exception message: Attempted to divide by zero."
res.Save(@"D:\dev\AsposeOmrTesting\AsposeOmrTesting\DebugFiles", "Template");

//Markup JSON
{
  "children": [
    {
      "element_type": "Page",
      "children": [
        {
          "element_type": "EmptyLine"
        },
        {
          "name": "1",
          "align": "Left",
          "element_type": "ChoiceBox",
          "answers_string": "(1) Offensive, Defensive, and Stability Operations\r\n  (2) Attack, Defend, and Screen\r\n  (3) Movement to Contact, Raid, and Delibrate Attack\r\n  (4) None of the Above\r\n ",
          "question_text": "The primary land operations conducted by the Army are:"
        },
        {
          "name": "3",
          "align": "Left",
          "element_type": "ChoiceBox",
          "answers_string": "(1) True\r\n  (2) False\r\n ",
          "question_text": "When conducting a deliberate attack, the Grendier can employ smoke to mark friendly and\r\n enemy positions."
        },
        {
          "name": "4",
          "align": "Left",
          "element_type": "ChoiceBox",
          "answers_string": "(1) True. The team should always use the same formation as the Squad.\r\n  (2) True. When the squad moves in a column of teams, the teams have better control when\r\n using a column formation.\r\n  (3) False. Teams can use different formations from the squad, based on terrain.\r\n  (4) False. Teams should use the Team line formation in order to maximize firepower to\r\n the front.\r\n ",
          "question_text": "When executing a movement via a squad column, the fire teams should also move in column\r\n formation."
        }
      ]
    }
  ],
  "element_type": "Template"
}

Any assistance would be greatly appreciated.

@Shonn

We were also able to notice this issue in our environment. Therefore, a ticket as OMRNET-405 has been logged in our issue tracking system for the sake of correction. We will further look into its details and let you know as soon as it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

I figured out why it is doing this. Your code is not allowing carriage return + line feed \r\n within the option text unless it is at the end of the sentence.

For example, this will work: “(A) True, fire is hot.\r\n”

However, this will throw an exception: “(A) True, fire is hot and depending on weather conditions \r\n there could be additional complications.\r\n”

I’m sure your developers will figure it out, but thought this might help you debug it.

@Shonn

Thanks for sharing your valuable findings. They have been recorded along with the ticket as well. We will investigate the ticket from this perspective as well and share our feedback with you.

@Shonn

The use of “\r\n” is not the best way to handle vertical choice boxes. We have a special element for it - VerticalChoiceBox. In the attached file, you can find your template created through VerticalChoiceBox.
OMRNET405.zip (85.4 KB)

This template automatically moves text according to container(Page) width. There is no need to look for a position in the text to put “\r\n”.

Also in the template, you will find Content elements responsible for the display of text and VerticalChoiceBox\Answer elements which are responsible for results in the .csv file.

By shortening the Name of VerticalChoiceBox and Answer elements you can reduce weight and simplify parsing of CSV file, without changing template display.

Got it. Thank you for your help!

1 Like