Hey yall,
I was trying to make a test app to mess with the microphone and ran into a crash. The following is my code
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/animation"
import "CoreLibs/easing"
local gfx <const> = playdate.graphics
local geom <const> = playdate.geometry
local snd <const> = playdate.sound
local recording_rect
local recording_indicator
local speed_rect
local speed_indicator
local sound_buffer
local player
function startup()
recording_rect = geom.rect.new(103, 3, 10, 10)
recording_indicator = geom.rect.new(3, 7, 10, 8)
speed_rect = geom.rect.new(103, 3, 10, 15)
speed_indicator = geom.rect.new(3, 7, 10, 13)
sound_buffer = snd.sample.new(5, snd.kFormat16bitMono)
if sound_buffer == nil then
print('Hey!!')
end
player = snd.sampleplayer.new(sound_buffer)
end
startup()
local rec_finished = false
function record_callback(buffer)
rec_finished = true
end
function playdate.update()
print("flag0")
if playdate.buttonIsPressed(playdate.kButtonB) then
print("flag1")
rec_finished = false
print("flag2")
snd.micinput.recordToSample(sound_buffer, record_callback)
print("flag3")
else
print("flag3.5")
-- stop recording ( if not stopped already)
if not rec_finished then
snd.micinput.stopRecording()
player:setSample(sound_buffer)
rec_finished = true
end
end
print("flag4")
if playdate.buttonIsPressed(playdate.kButtonA) and not playdate.isButtonPressed(playdate.kButtonB) then
if not player:isPlaying() then
player:play()
end
end
print("flag5")
end
Which produces the following output upon pressing B (note that flag0
, flag4
, and flag5
are spammed in console as expected)
flag0
flag1
flag2
flag3
flag4
flag5
update failed: lua_exec() expected 2 item on stack, but it has 4
This implies that the lua update function completes, and crashes before re-entering.
Hopefully I'm just making a dumb mistake somewhere!