Look and Feel function running into undefined data when pulling from a Global
-
Here's a shortened, trimmed version of what I have. It's scattered across multiple import scripts but this is the order of execution/import.
const var FONT_SIZE = 20; const var ControlProperties = {}; // I make controls using a helper function so i can pass a bunch of properties in an object // and query (the existence of) these properties from the ControlProperties later on inline function createSlider (param) { ControlProperties[param.id] = param; // make input parameters accessible local widget = Content.addKnob(param.id, param.x, param.y); // set up the slider, assign properties and do a bunch of stuff // once all is done, assign look and feel object and return the reference if (param.lookAndFeelObject) widget.setLocalLookAndFeel(param.lookAndFeelObject); return widget; } // set up a look and feel object // the function refers to the correct ControlProperties property by pulling obj.id so it can access // the relevant data for each control it's painting const var settingsSlider = Content.createLocalLookAndFeel(); settingsSlider.registerFunction("drawRotarySlider", function(g, obj) { var a = obj.area; var p = ControlProperties[obj.id]; var fontSize = p.fontSize; g.drawAlignedText(obj.text, obj.area, "centred"); }); // const var volumeSlider = createSlider( { "id": "volumeSlider", "text": "Volume Slider", "x": 10, "y": 10, "fontSize": FONT_SIZE, "lookAndFeelObject": settingsSlider, }); // 9 more createSlider function calls to make more sliders..
And it works fine, exactly as I want it to. But if we change ControlProperties into a global
global ControlProperties = {};
all hell breaks loose on the first run only. Everywhere the laf function attempts to get data from ControlProperties, it runs into
undefined
. So for the very first run (that if you're using globals, since globals reset into "Recompile all" has not yet been implemented, can only be properly simulated by closing and reopening HISE), the interface is all messed up and the console warns of undefined variables in use for every singlecreateSlider
call i.e. every attempt to set LLAF object to a control.