# Device freezes when using simple Lua function \[SOLVED\]

**URL:** <https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051>\
**Category:** Bug reports\
**Created:** [November 7, 2021, 11:06am UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051 "2021-11-07T11:06:52Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 7, 2021, 11:06am UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/1 "2021-11-07T11:06:52Z")

</div>

My device keeps freezing.  
It only freezes on the controls that have the `oscPairSelect1()` and `oscPairSelect2()` function assigned in the json.  
Do I am doing something wrong here?  
The function seems to do what it supposed to do. It sends 1 osc pair select message until we switch to the other pair.

You can replicate it by loading this preset.  
Just go to the “OSC PAIR1” or “OSC PAIR2” page and keep twisting the “OSC fine” but any other control will do.  
At some point the Electra One freezes. But in the console app nothing appears in the logs.

The template:  
[[[Electra One App](https://app.electra.one/preset/tRXblONvwPE7d23u416u)]]

.epr file:  
[Ensoniq Mirage Soundprocess (14).epr](https://forum.electra.one/uploads/short-url/gshSHBEGChtlaLSCzqO0XlKPZDQ.epr) (74.7 KB)

Lua script

```auto
mirageSoundProcessDeviceId = 9

incCount1 = 1

incCount2 = 1

-- getPatchNumberByte function is added in the patch request and reponse in the json
-- it fetches the value from parameterNumber 40 (patch select) on the moment the patch request button is pressed
-- so that the same patch is requested as parameterNumber 40 (patch select) is set to.
function getPatchNumberByte()
local parameterNumber = 40

patchNumber = parameterMap.get (mirageSoundProcessDeviceId, PT_SYSEX, parameterNumber )

return (patchNumber)

end

-- oscPairSelect1 and oscPairSelect2 send a osc pair select message once, after that reset the counter of the other function. 
-- so if we switch to that page the corresponding osc pair select message is send out once again.
-- controls belonging to osc pair 1 have the function oscPairSelect1 added in the json .epr file and controls osc pair 2 
-- oscPairSelect2

function oscPairSelect1()

if incCount1 == 1 then
 device = devices.get (mirageSoundProcessDeviceId)
 midi.sendSysex (PORT_1, { 0, 0, 35, 1, 67, 60, 1, 0 })
 incCount1 = incCount1 + 1
-- reset the other counter so the message will be send for pair 2 once we switch to that controls 
incCount2 = 1
 end

end

function oscPairSelect2()

if incCount2 == 1 then
 device = devices.get (mirageSoundProcessDeviceId)
 midi.sendSysex (PORT_1, { 0, 0, 35, 1, 67, 60, 2, 0 })
 incCount2 = incCount2 + 1

incCount1 = 1
 end

end

```

---

<div class="post-metadata">

**Author:** ![oldgearguy](https://avatars.discourse-cdn.com/v4/letter/o/f4b2a3/32.png) [@oldgearguy](https://forum.electra.one/u/oldgearguy)\
**Post date:** [November 7, 2021, 7:35pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/2 "2021-11-07T19:35:08Z")

</div>

I don’t have a Mirage, but the template (with the LUA code pasted in) does not lock up no matter how much I twist.  
Maybe the Mirage is sending back something that is causing a problem?

Try unplugging the MIDI Out from the Mirage and see what happens, but here, with lots of twisting, no lockup.

(and believe me - I’ve been locking up my ElectraOne and/or PC quite a bit during my preset development…)

---

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 7, 2021, 8:04pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/3 "2021-11-07T20:04:19Z")

</div>

hey thanks for checking.  
it lock up for me as well when the Mirage is disconnected.  
So its not the mirage.

---

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 7, 2021, 8:05pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/4 "2021-11-07T20:05:28Z")

</div>

did you twist knob on the oscillator pages? the controls trigger the osc pair select function.

---

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 8, 2021, 8:04am UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/5 "2021-11-08T08:04:42Z")

</div>

I have cleared all my presets by sending an empty one to all the slots.  
Then reloaded the presets and the issue persists.  
I then re-flashed the firmware, templates where not affected but the issue still persist.

Only when I keep twisting a know which have the oscPairSelect funtions attached this issue occurs.

---

<div class="post-metadata">

**Author:** ![oldgearguy](https://avatars.discourse-cdn.com/v4/letter/o/f4b2a3/32.png) [@oldgearguy](https://forum.electra.one/u/oldgearguy)\
**Post date:** [November 8, 2021, 11:54am UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/6 "2021-11-08T11:54:18Z")

</div>

yes, I was on the oscillator pages as you mentioned. I was rotating the Fine controls for both and then twisting other knobs and it was stable for me. I can try some other tests later today if that same template is still a problem.

---

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 8, 2021, 12:39pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/7 "2021-11-08T12:39:06Z")

</div>

That would be great.  
You have to really keep rotating the “fine controll” or others for a while.  
I loaded the preset and lua code via [Electra One App](https://app.electra.one/sandbox/) and after uploading I kept dialing “OSC A Fine” after a while the Electra One froze up.

---

<div class="post-metadata">

**Author:** ![oldgearguy](https://avatars.discourse-cdn.com/v4/letter/o/f4b2a3/32.png) [@oldgearguy](https://forum.electra.one/u/oldgearguy)\
**Post date:** [November 8, 2021, 9:10pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/8 "2021-11-08T21:10:28Z")

</div>

I did get it to lock up. **But** only when I had the log console running. If I was not in the App Editor and did not have the console log running, it never locked up. With the console log open, the controls began to stutter and not change values, then locked up solid.

---

<div class="post-metadata">

**Author:** ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)\
**Post date:** [November 8, 2021, 9:13pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/9 "2021-11-08T21:13:27Z")

</div>

hmm. I will replicate it to see what is happening there. Thanks for providing all the input!

---

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 8, 2021, 9:16pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/10 "2021-11-08T21:16:46Z")

</div>

I have the same issue with the Electra One just connected to usb power not to a computer.

---

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 11, 2021, 11:32am UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/11 "2021-11-11T11:32:37Z")

</div>

Hi Martin, would you have time to look at this sometime?

I have been trying to make it work but the Electra One keeps freezing.

It’s not a pleasant experience editing the mirage and having to restart the one so often meanwhile loosing all parameter settings.

I you have another solution to make the “oscillator pair 1 or 2 select work” that is fine by me.

Cheers Tim

---

<div class="post-metadata">

**Author:** ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)\
**Post date:** [November 11, 2021, 12:13pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/12 "2021-11-11T12:13:46Z")

</div>

Hi Tim, I have it on my todo. I had a few moments when I planned to sit down and review it. Unfortunately, we are quite overwhelmed with number of orders coming in and I want to make sure people will get their Electras on time. It feels it will be a little bit calmer today, if I have a moment, this is really high up on my list. With other few issues reported by other users lately.

---

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 11, 2021, 1:25pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/13 "2021-11-11T13:25:47Z")

</div>

Hi Martin, sure understand. Will be more patient.

I did some tests  
I use the e.one console to read the memory consumption.

1 made 2 controls both with a function assigned: oscPairSelect1() and oscPairSelect2()  
Same lua code is used in 2 presets. 1 with 2 controls and another with many copies of a control ( to saturate the memory ), I found that commented out data is not send to the e.one.

```auto
mirageSoundProcessDeviceId = 1
incCount1 = 1
incCount2 = 1

function oscPairSelect1()

if incCount1 == 1 then
device = devices.get (mirageSoundProcessDeviceId)
 midi.sendSysex (PORT_1, { 0, 0, 35, 1, 67, 60, 1, 0 })

 incCount1 = incCount1 + 1

incCount2 = 1

 end

end

function oscPairSelect2()

if incCount2 == 1 then
 device = devices.get (mirageSoundProcessDeviceId)
 midi.sendSysex (PORT_1, { 0, 0, 35, 1, 67, 60, 2, 0 })
 incCount2 = incCount2 + 1

incCount1 = 1
 end

end

```

2 controls [2 controlls.epr](https://forum.electra.one/uploads/short-url/aSrAUHKVlj8CMiGRtJntgkRSrw1.epr) (1.4 KB)

1. the preset with controls does not freeze.
2. The electra one console shows “2 controls” above the free memory bar.
3. 73 % free memory is indicated

many controls copied [many controls.epr](https://forum.electra.one/uploads/short-url/rjJ2LVHGWLND9TzaWuJwpVr2T7k.epr) (207.7 KB)

1. the preset with “many controls” freezes,
2. only 15 % free ram is indicated
3. the console app shows “no preset” above the memory indicator

many controls unique  
[many controls unique.epr](https://forum.electra.one/uploads/short-url/uSXLppOEnv8f0d8vZU55AOS1UxF.epr) (48.2 KB)

1. the preset with “many controls unique” freezes,
2. only 46 % free ram is indicated
3. the console app shows “many controls unique” above the memory indicator

---

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 11, 2021, 1:49pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/14 "2021-11-11T13:49:50Z")

</div>

`collectgarbage("collect")`  
Adding a single cycle garbage collection works as a workaround. My template does not freeze anymore.

`collectgarbage("count")`  
Adding only to print the gc count to the end of the function in the “many controls” template and the e.one gets crazy. Some distortion on the display and its freezes after a while when twisting the knops.

[freeze-and-gc-count.txt](https://forum.electra.one/uploads/short-url/ksot9modKomnFP7oYhI5obDC10S.txt) (170.4 KB)

Anyhow I have a workaround. Hope this helps cheers T

---

<div class="post-metadata">

**Author:** ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)\
**Post date:** [November 12, 2021, 9:28pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/15 "2021-11-12T21:28:07Z")

</div>

Hi Tim, thanks for your input! I was able to replicate the issue and I have a good fix for it. It will be resolved in the upcoming release.

---

<div class="post-metadata">

**Author:** ![Flyweight](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/flyweight/32/342_2.png) [@Flyweight](https://forum.electra.one/u/Flyweight)\
**Post date:** [November 12, 2021, 9:36pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/16 "2021-11-12T21:36:25Z")

</div>

Wow you are fast! great, looking forward to a new juicy release

Of of curiosity does your fix have to do with the garbage collector setup of the lua interpreter?

Thanks a lot

Cheers Tim

---

<div class="post-metadata">

**Author:** ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)\
**Post date:** [November 15, 2021, 6:49am UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/17 "2021-11-15T06:49:44Z")

</div>

Yup, it was related to the the garbage collection. Your and @oldgearguy input helped me to locate and fix the issue. Thanks for that!

The fix is ready and was verified to work. It will be included in the upcoming release.

---

<div class="post-metadata">

**Author:** ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)\
**Post date:** [November 25, 2021, 10:47pm UTC](https://forum.electra.one/t/device-freezes-when-using-simple-lua-function-solved/1051/18 "2021-11-25T22:47:49Z")

</div>

fixed in release 2.1.4
