请选择 进入手机版 | 继续访问电脑版
返回官网官方微博

麦步社区-论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
热搜: MAI 表盘
查看: 3524|回复: 4

求大牛们解惑

[复制链接]

11

主题

65

帖子

1878

麦力

精华
0
阅读权限
30
在线时间
73 小时

发表于 2017-9-1 14:37:30 | 显示全部楼层 |阅读模式
下边的代码,为啥count>100后程序就死掉了(我只在模拟器上跑来着)

编辑器自动生成的变量名称,有些怪,还望凑合着看看

难不成不能用重建窗口的方法来模拟刷新吗?

//-------下边是代码------
//---include
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "maibu_sdk.h"
#include "maibu_res.h"

#include <time.h>
#include <math.h>

P_Window CreateNewWindowByIndex(int8_t windowIndex);//通过序号创建窗口
P_Window CreateWindow_WinWindow1();

void RefreshTimeValue();
void RefreshCurrentWindow();//刷新(重新载入)当前窗口

static int32_t currentWindowId = -1;//当前窗口Id

//时间变量
static double SystemInner_Hour;
static double SystemInner_Minute;
static double SystemInner_Second;

static uint8_t WinWindow1_TgTimer1_Timer_Id;

static uint8_t count;//测试用

//窗口(窗口1)计时器(计时器1)过程
void WinWindow1_TgTimer1_Timer(date_time_t tick,uint32_t millis,void *context)
{
        count++;

        app_service_timer_unsubscribe(WinWindow1_TgTimer1_Timer_Id);

        //RefreshTimeValue();
        RefreshCurrentWindow();
}

//刷新时间值
void RefreshTimeValue()
{
        struct date_time nowTime;
        app_service_get_datetime(&nowTime);
        SystemInner_Hour = nowTime.hour;
        SystemInner_Minute = nowTime.min;
        SystemInner_Second = nowTime.sec;
}

//刷新当前窗口过程
void RefreshCurrentWindow()
{
        if(currentWindowId<=0)
        {
                return;
        }
        //RefreshTimeValue();
        P_Window oldWin = (P_Window)app_window_stack_get_window_by_id(currentWindowId);
        P_Window newWin = (P_Window)(P_Window)CreateWindow_WinWindow1();
        currentWindowId = app_window_stack_replace_window(oldWin,newWin);
}

//创建窗口(窗口1)的单行文字图层(单行文字1)
P_Layer CreateSingleLineTextLayer_WinWindow1_CtlSLText1()
{
        GRect frame_sl_CtlSLText1 = {{11,20}, {28,109}};
        unsigned char buf_sl_CtlSLText1[20];
        sprintf(buf_sl_CtlSLText1,"%02f",SystemInner_Second);
        LayerText text_sl_CtlSLText1 = {buf_sl_CtlSLText1, frame_sl_CtlSLText1, GAlignCenter, U_GBK_SIMSUN_12};
        P_Layer retLayer = app_layer_create_text(&text_sl_CtlSLText1);
        return retLayer;
}

//创建窗口(窗口1)的单行文字图层(单行文字2)
P_Layer CreateSingleLineTextLayer_WinWindow1_CtlSLText2()
{
        GRect frame_sl_CtlSLText1 = {{11,40}, {28,109}};
        unsigned char buf_sl_CtlSLText1[20];
        sprintf(buf_sl_CtlSLText1,"%02d",count);
        LayerText text_sl_CtlSLText1 = {buf_sl_CtlSLText1, frame_sl_CtlSLText1, GAlignCenter, U_GBK_SIMSUN_12};
        P_Layer retLayer = app_layer_create_text(&text_sl_CtlSLText1);
        return retLayer;
}

//---window
//创建窗口WinWindow1(窗口1)
P_Window CreateWindow_WinWindow1()
{
        P_Window p_window = app_window_create();
        P_Layer layer;

        //载入窗口(窗口1)的单行文字图层(单行文字1)
        //app_window_add_layer(p_window, CreateSingleLineTextLayer_WinWindow1_CtlSLText1());
        //载入窗口(窗口1)的单行文字图层(单行文字2)
        app_window_add_layer(p_window, CreateSingleLineTextLayer_WinWindow1_CtlSLText2());

        //注册计时器事件(如果存在)
        app_service_timer_unsubscribe(WinWindow1_TgTimer1_Timer_Id);
        WinWindow1_TgTimer1_Timer_Id = app_service_timer_subscribe(100,WinWindow1_TgTimer1_Timer,NULL);

        //返回
        return p_window;
}

//---main
int main()
{
        simulator_init();
        //压入启动窗口
        P_Window p_window = (P_Window)CreateWindow_WinWindow1();
        currentWindowId = app_window_stack_push(p_window);
        simulator_wait();
}



3

主题

118

帖子

1223

麦力

精华
1
阅读权限
150
在线时间
59 小时
发表于 2017-9-1 15:36:20 | 显示全部楼层
模拟器中线程限制是100个,app_service_timer_unsubscribe并没有销毁该线程,只是标识为不可用。所以超出了100个,就溢出异常了。一般在创建好窗口后,只要创建一个后台定时器就可以了。不需要反复的创建和销毁。

11

主题

65

帖子

1878

麦力

精华
0
阅读权限
30
在线时间
73 小时

 楼主| 发表于 2017-9-1 15:39:38 | 显示全部楼层
mark 发表于 2017-9-1 15:36
模拟器中线程限制是100个,app_service_timer_unsubscribe并没有销毁该线程,只是标识为不可用。所以超出了 ...

懂了!谢谢大牛!
已经顺利调试通过了

0

主题

5

帖子

110

麦力

精华
0
阅读权限
20
在线时间
6 小时

发表于 2017-10-18 03:06:51 | 显示全部楼层
mark 发表于 2017-9-1 15:36
模拟器中线程限制是100个,app_service_timer_unsubscribe并没有销毁该线程,只是标识为不可用。所以超出了 ...

请问,这种限制哪里有系统的参考和说明?

3

主题

118

帖子

1223

麦力

精华
1
阅读权限
150
在线时间
59 小时
发表于 2017-10-18 16:02:03 | 显示全部楼层
这个是模拟器中的参数,和手表中的机制不一样的。手表参考开发文档。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|麦步官方论坛 ( 粤ICP备12052190号  

GMT+8, 2024-3-29 22:23 , Processed in 0.077365 second(s), 24 queries .

Powered by Discuz! X3.2

© 2012-2021 Comsenz Inc.

快速回复 返回顶部 返回列表