mirror of
https://github.com/defold/extension-camera
synced 2025-06-27 10:27:45 +02:00
Fixed crash when running start_capture a second time
This commit is contained in:
parent
49f954ae04
commit
652242fe85
@ -390,6 +390,7 @@ int CameraPlatform_StopCapture()
|
||||
{
|
||||
[g_Camera.m_Delegate stopCamera];
|
||||
[g_Camera.m_Delegate release];
|
||||
g_Camera.m_Delegate = 0;
|
||||
|
||||
dmBuffer::Destroy(g_Camera.m_VideoBuffer);
|
||||
g_Camera.m_VideoBuffer = 0;
|
||||
|
@ -0,0 +1,12 @@
|
||||
key_trigger {
|
||||
input: KEY_SPACE
|
||||
action: "space"
|
||||
}
|
||||
mouse_trigger {
|
||||
input: MOUSE_BUTTON_1
|
||||
action: "touch"
|
||||
}
|
||||
touch_trigger {
|
||||
input: TOUCH_MULTI
|
||||
action: "touch"
|
||||
}
|
@ -77,6 +77,116 @@ embedded_instances {
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"embedded_components {\n"
|
||||
" id: \"label\"\n"
|
||||
" type: \"label\"\n"
|
||||
" data: \"size {\\n"
|
||||
" x: 128.0\\n"
|
||||
" y: 32.0\\n"
|
||||
" z: 0.0\\n"
|
||||
" w: 0.0\\n"
|
||||
"}\\n"
|
||||
"scale {\\n"
|
||||
" x: 1.0\\n"
|
||||
" y: 1.0\\n"
|
||||
" z: 1.0\\n"
|
||||
" w: 0.0\\n"
|
||||
"}\\n"
|
||||
"color {\\n"
|
||||
" x: 1.0\\n"
|
||||
" y: 1.0\\n"
|
||||
" z: 1.0\\n"
|
||||
" w: 1.0\\n"
|
||||
"}\\n"
|
||||
"outline {\\n"
|
||||
" x: 0.0\\n"
|
||||
" y: 0.0\\n"
|
||||
" z: 0.0\\n"
|
||||
" w: 1.0\\n"
|
||||
"}\\n"
|
||||
"shadow {\\n"
|
||||
" x: 0.0\\n"
|
||||
" y: 0.0\\n"
|
||||
" z: 0.0\\n"
|
||||
" w: 1.0\\n"
|
||||
"}\\n"
|
||||
"leading: 1.0\\n"
|
||||
"tracking: 0.0\\n"
|
||||
"pivot: PIVOT_NW\\n"
|
||||
"blend_mode: BLEND_MODE_ALPHA\\n"
|
||||
"line_break: false\\n"
|
||||
"text: \\\"Space/Touch to toggle capture\\\"\\n"
|
||||
"font: \\\"/builtins/fonts/system_font.font\\\"\\n"
|
||||
"material: \\\"/builtins/fonts/label.material\\\"\\n"
|
||||
"\"\n"
|
||||
" position {\n"
|
||||
" x: 90.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"embedded_components {\n"
|
||||
" id: \"status\"\n"
|
||||
" type: \"label\"\n"
|
||||
" data: \"size {\\n"
|
||||
" x: 128.0\\n"
|
||||
" y: 32.0\\n"
|
||||
" z: 0.0\\n"
|
||||
" w: 0.0\\n"
|
||||
"}\\n"
|
||||
"scale {\\n"
|
||||
" x: 1.0\\n"
|
||||
" y: 1.0\\n"
|
||||
" z: 1.0\\n"
|
||||
" w: 0.0\\n"
|
||||
"}\\n"
|
||||
"color {\\n"
|
||||
" x: 1.0\\n"
|
||||
" y: 1.0\\n"
|
||||
" z: 1.0\\n"
|
||||
" w: 1.0\\n"
|
||||
"}\\n"
|
||||
"outline {\\n"
|
||||
" x: 0.0\\n"
|
||||
" y: 0.0\\n"
|
||||
" z: 0.0\\n"
|
||||
" w: 1.0\\n"
|
||||
"}\\n"
|
||||
"shadow {\\n"
|
||||
" x: 0.0\\n"
|
||||
" y: 0.0\\n"
|
||||
" z: 0.0\\n"
|
||||
" w: 1.0\\n"
|
||||
"}\\n"
|
||||
"leading: 1.0\\n"
|
||||
"tracking: 0.0\\n"
|
||||
"pivot: PIVOT_NW\\n"
|
||||
"blend_mode: BLEND_MODE_ALPHA\\n"
|
||||
"line_break: false\\n"
|
||||
"text: \\\"label\\\\n"
|
||||
"\\\"\\n"
|
||||
" \\\"\\\"\\n"
|
||||
"font: \\\"/builtins/fonts/system_font.font\\\"\\n"
|
||||
"material: \\\"/builtins/fonts/label.material\\\"\\n"
|
||||
"\"\n"
|
||||
" position {\n"
|
||||
" x: 90.0\n"
|
||||
" y: -24.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
""
|
||||
position {
|
||||
x: 95.39966
|
||||
|
@ -1,12 +1,20 @@
|
||||
|
||||
function init(self)
|
||||
local logosize = 128
|
||||
local screen_width = sys.get_config("display.width", 600)
|
||||
local screen_height = sys.get_config("display.height", 800)
|
||||
local scale_width = screen_width / logosize
|
||||
local scale_height = screen_height / logosize
|
||||
local function stop_capture(self)
|
||||
if self.cameraframe == nil then
|
||||
return
|
||||
end
|
||||
|
||||
go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) )
|
||||
self.cameraframe = nil
|
||||
camera.stop_capture()
|
||||
|
||||
label.set_text("logo#status", "Capture Status: OFF")
|
||||
end
|
||||
|
||||
|
||||
local function start_capture(self)
|
||||
if self.cameraframe ~= nil then
|
||||
return
|
||||
end
|
||||
|
||||
if camera ~= nil then
|
||||
|
||||
@ -31,11 +39,28 @@ function init(self)
|
||||
format=resource.TEXTURE_FORMAT_RGB,
|
||||
num_mip_maps=1 }
|
||||
end
|
||||
label.set_text("logo#status", "Capture Status: ON")
|
||||
else
|
||||
print("could not start camera capture")
|
||||
label.set_text("logo#status", "Capture Status: UNAVAILABLE")
|
||||
end
|
||||
end
|
||||
|
||||
function init(self)
|
||||
msg.post(".", "acquire_input_focus")
|
||||
|
||||
local logosize = 128
|
||||
local screen_width = sys.get_config("display.width", 600)
|
||||
local screen_height = sys.get_config("display.height", 800)
|
||||
local scale_width = screen_width / logosize
|
||||
local scale_height = screen_height / logosize
|
||||
|
||||
go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) )
|
||||
|
||||
|
||||
start_capture(self)
|
||||
end
|
||||
|
||||
function final(self)
|
||||
if self.cameraframe ~= nil then
|
||||
camera.stop_capture()
|
||||
@ -44,10 +69,20 @@ end
|
||||
|
||||
|
||||
function update(self, dt)
|
||||
if self.cameraframe then
|
||||
if self.cameraframe ~= nil then
|
||||
local pathmodelcamera = go.get("#sprite", "texture0")
|
||||
resource.set_texture(pathmodelcamera, self.cameratextureheader, self.cameraframe)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
function on_input(self, action_id, action)
|
||||
if (action_id == hash("space") or action_id == hash("touch")) and action.pressed then
|
||||
if self.cameraframe == nil then
|
||||
start_capture(self)
|
||||
else
|
||||
stop_capture(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user