[TemplatedMultiContent] Bug in "default" template handling

Issue #708 new
prl created an issue

There is an error in TemplatedMultiContent.__init__() in handling the item height in a default template when it is converted to be used as a template when TemplatedMultiContent.source.style is None.

If a default template is used in this way:

{
  "templates": {
    "default": [
      38,  # itemHeight
      [
        MultiContentEntryText(pos=(0, 0), size=(503, 28), font=1, text=1),
      ]
    ],
    ...
  }
}

then in TemplatedMultiContent.__init__():

if not "template" in self.template: # default template can be ["template"] or ["templates"]["default"]
    self.template["template"] = self.template["templates"]["default"][1]
    self.template["itemHeight"] = self.template["template"][0]

self.template["itemHeight"] will be effectively set to self.template["templates"]["default"][1][0], which is the value returned by MultiContentEntryText(pos=(0, 0), size=(503, 28), font=1, text=1). It should be set to the default template's item height, which is self.template["templates"]["default"][0], i.e. 38.

I encountered this but when I tried to create a minimal default template as "default": [0, []]. This caused an IndexError exception in TemplatedMultiContent.__init__(). The bug can be worked around with a minimal default template of "default": [0, [None]]. But any actual use of the item height assigned in the above code will cause an exception, whether the workaround is used or not. This seems to be avoided because the code avoids making use of that item height.

I have marked this as minor, but I would have marked it as major if it actually affected existing cone and skins.

Comments (0)

  1. Log in to comment