diff --git a/Info.plist b/Info.plist
index 685054c..c5ac1ab 100644
--- a/Info.plist
+++ b/Info.plist
@@ -37,9 +37,7 @@
NSPrincipalClass
NSApplication
NSCameraUsageDescription
- App Needs to use camera to take Profile picture
- NSPhotoLibraryAddUsageDescription
- App Needs to store your photos
+ {{project.title}} needs to use the camera
{{#display.high_dpi}}
NSHighResolutionCapable
diff --git a/camera/src/camera.cpp b/camera/src/camera.cpp
index bc6a948..bd1c3b2 100644
--- a/camera/src/camera.cpp
+++ b/camera/src/camera.cpp
@@ -34,7 +34,6 @@ struct DefoldCamera
DefoldCamera g_DefoldCamera;
-
void Camera_QueueMessage(CameraStatus status)
{
DM_MUTEX_SCOPED_LOCK(g_DefoldCamera.m_Mutex);
@@ -58,6 +57,20 @@ static void Camera_ProcessQueue()
break;
}
CameraStatus status = g_DefoldCamera.m_MessageQueue[i];
+
+ if (status == STATUS_STARTED)
+ {
+ // Increase ref count
+ dmScript::LuaHBuffer luabuffer = {g_DefoldCamera.m_VideoBuffer, false};
+ dmScript::PushBuffer(L, luabuffer);
+ g_DefoldCamera.m_VideoBufferLuaRef = dmScript::Ref(L, LUA_REGISTRYINDEX);
+ }
+ else if (status == STATUS_STOPPED)
+ {
+ dmScript::Unref(L, LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef); // We want it destroyed by the GC
+ g_DefoldCamera.m_VideoBufferLuaRef = 0;
+ }
+
lua_pushnumber(L, (lua_Number)status);
int ret = lua_pcall(L, 2, 0, 0);
if (ret != 0)
@@ -90,11 +103,6 @@ static int StartCapture(lua_State* L)
CameraPlatform_StartCapture(&g_DefoldCamera.m_VideoBuffer, type, quality, g_DefoldCamera.m_Params);
- // Increase ref count
- dmScript::LuaHBuffer luabuffer = {g_DefoldCamera.m_VideoBuffer, false};
- dmScript::PushBuffer(L, luabuffer);
- g_DefoldCamera.m_VideoBufferLuaRef = dmScript::Ref(L, LUA_REGISTRYINDEX);
-
return 1;
}
@@ -104,7 +112,6 @@ static int StopCapture(lua_State* L)
CameraPlatform_StopCapture();
- dmScript::Unref(L, LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef); // We want it destroyed by the GC
return 0;
}
@@ -132,7 +139,14 @@ static int GetInfo(lua_State* L)
static int GetFrame(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 1);
- lua_rawgeti(L,LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef);
+ if (g_DefoldCamera.m_VideoBufferLuaRef != 0)
+ {
+ lua_rawgeti(L, LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef);
+ }
+ else
+ {
+ lua_pushnil(L);
+ }
return 1;
}
diff --git a/main/main.script b/main/main.script
index 40d2ed1..51dad22 100644
--- a/main/main.script
+++ b/main/main.script
@@ -17,11 +17,10 @@ local function start_capture(self)
return
end
- local sysinfo = sys.get_sys_info()
-
local quality = camera.CAPTURE_QUALITY_HIGH
+
local type = camera.CAMERA_TYPE_FRONT
- if sysinfo.system_name == 'iPhone OS' then
+ if sys.get_sys_info().system_name == 'iPhone OS' then
type = camera.CAMERA_TYPE_BACK
quality = camera.CAPTURE_QUALITY_MEDIUM
end
@@ -30,11 +29,13 @@ local function start_capture(self)
if status == camera.STATUS_STARTED then
self.cameraframe = camera.get_frame()
self.camerainfo = camera.get_info()
- self.cameratextureheader = {width=self.camerainfo.width,
- height=self.camerainfo.height,
- type=resource.TEXTURE_TYPE_2D,
- format=resource.TEXTURE_FORMAT_RGB,
- num_mip_maps=1 }
+ self.cameratextureheader = {
+ width=self.camerainfo.width,
+ height=self.camerainfo.height,
+ type=resource.TEXTURE_TYPE_2D,
+ format=resource.TEXTURE_FORMAT_RGB,
+ num_mip_maps=1
+ }
label.set_text("logo#status", "Capture Status: ON")
else
label.set_text("logo#status", "Capture Status: ERROR")
@@ -53,19 +54,18 @@ function init(self)
go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) )
-
start_capture(self)
end
function final(self)
- if self.cameraframe ~= nil then
+ if self.cameraframe then
camera.stop_capture()
end
end
function update(self, dt)
- if self.cameraframe ~= nil then
+ if self.cameraframe then
local pathmodelcamera = go.get("#sprite", "texture0")
resource.set_texture(pathmodelcamera, self.cameratextureheader, self.cameraframe)
end
@@ -74,10 +74,10 @@ 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
+ if self.cameraframe then
stop_capture(self)
+ else
+ start_capture(self)
end
end
end