{"action":"created","issue":{"url":"https://api.github.com/repos/littlevgl/pc_simulator/issues/12","repository_url":"https://api.github.com/repos/littlevgl/pc_simulator","labels_url":"https://api.github.com/repos/littlevgl/pc_simulator/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/littlevgl/pc_simulator/issues/12/comments","events_url":"https://api.github.com/repos/littlevgl/pc_simulator/issues/12/events","html_url":"https://github.com/littlevgl/pc_simulator/issues/12","id":310668107,"node_id":"MDU6SXNzdWUzMTA2NjgxMDc=","number":12,"title":"Workaround to run under MacOS","user":{"login":"margce","id":13647561,"node_id":"MDQ6VXNlcjEzNjQ3NTYx","avatar_url":"https://avatars2.githubusercontent.com/u/13647561?v=4","gravatar_id":"","url":"https://api.github.com/users/margce","html_url":"https://github.com/margce","followers_url":"https://api.github.com/users/margce/followers","following_url":"https://api.github.com/users/margce/following{/other_user}","gists_url":"https://api.github.com/users/margce/gists{/gist_id}","starred_url":"https://api.github.com/users/margce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/margce/subscriptions","organizations_url":"https://api.github.com/users/margce/orgs","repos_url":"https://api.github.com/users/margce/repos","events_url":"https://api.github.com/users/margce/events{/privacy}","received_events_url":"https://api.github.com/users/margce/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-03T02:06:07Z","updated_at":"2018-08-19T11:26:35Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI just started using the PC_SIMULATOR under MacOS 10.12.6 and I ran into the following issue.\r\n\r\nUsing the default source code when running the pc_simulator application the app crashes with the following message\r\n\r\n```\r\nMartins-MacBook-Pro:Debug tinno$ ./pc_simulator\r\n2018-04-03 10:17:46.692 pc_simulator[4326:483915] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'\r\n*** First throw call stack:\r\n(\r\n\t0   CoreFoundation                      0x00007fffcdaaf2cb __exceptionPreprocess + 171\r\n\t1   libobjc.A.dylib                     0x00007fffe28c648d objc_exception_throw + 48\r\n\t2   AppKit                              0x00007fffcbc98e82 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 4480\r\n\t3   SDL2                                0x00000001056195f5 SDL2 + 140789\r\n\t4   SDL2                                0x00000001056038dd SDL2 + 51421\r\n\t5   pc_simulator                        0x00000001053faa5b sdl_refr + 395\r\n\t6   SDL2                                0x00000001056176ac SDL2 + 132780\r\n\t7   SDL2                                0x0000000105617139 SDL2 + 131385\r\n\t8   libsystem_pthread.dylib             0x00007fffe33c593b _pthread_body + 180\r\n\t9   libsystem_pthread.dylib             0x00007fffe33c5887 _pthread_body + 0\r\n\t10  libsystem_pthread.dylib             0x00007fffe33c508d thread_start + 13\r\n)\r\nlibc++abi.dylib: terminating with uncaught exception of type NSException\r\nAbort trap: 6\r\n```\r\n\r\nThis seems to be due to the fact that you can't Poll from event outside the main thread, at least it seems to be an issue on MacOS, I don't have experience with SDL. Currently monitor.c initialises SDL and monitors for mouse and keyboard events.\r\n\r\nTo workaround this issue, what I did was.\r\n\r\nI modified monitor_init() so that the SDL initialisation is done from main.c thread like so,\r\n\r\n```\r\nvoid monitor_init(void)\r\n{\r\n\t/*Initialize the SDL*/\r\n    SDL_Init(SDL_INIT_VIDEO);\r\n\r\n    SDL_SetEventFilter(quit_filter, NULL);\r\n\r\n\twindow = SDL_CreateWindow(\"TFT Simulator\",\r\n\t\tSDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,\r\n\t\tMONITOR_HOR_RES, MONITOR_VER_RES, 0);       /*last param. SDL_WINDOW_BORDERLESS to hide borders*/\r\n\r\n\trenderer = SDL_CreateRenderer(window, -1, 0);\r\n\ttexture = SDL_CreateTexture(renderer,\r\n\t\tSDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, MONITOR_VER_RES);\r\n\r\n\t/*Initialize the frame buffer to gray (77 is an empirical value) */\r\n\tmemset(tft_fb, 77, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t));\r\n\tSDL_UpdateTexture(texture, NULL, tft_fb, MONITOR_HOR_RES * sizeof(uint32_t));\r\n\tsdl_refr_qry = true;\r\n\r\n\tSDL_CreateThread(sdl_refr, \"sdl_refr\", NULL);\r\n\twhile(sdl_inited == false); /*Wait until 'sdl_refr' initializes the SDL*/\r\n}\r\n```\r\n\r\nI then modified the monitor thread to just do the drawing routines,\r\n\r\n```\r\nstatic int sdl_refr(void * param)\r\n{\r\n    (void)param;\r\n\tsdl_inited = true;\r\n\r\n\t/*Run until quit event not arrives*/\r\n\twhile(sdl_quit_qry == false) {\r\n\r\n\t\t/*Refresh handling*/\r\n\t\tif(sdl_refr_qry != false) {\r\n            sdl_refr_qry = false;\r\n            SDL_UpdateTexture(texture, NULL, tft_fb, MONITOR_HOR_RES * sizeof(uint32_t));\r\n            SDL_RenderClear(renderer);\r\n            SDL_RenderCopy(renderer, texture, NULL, NULL);\r\n            SDL_RenderPresent(renderer);\r\n\t\t}\r\n\r\n\t\t/*Sleep some time*/\r\n\t\tSDL_Delay(SDL_REFR_PERIOD);\r\n\t}\r\n\r\n\tSDL_DestroyTexture(texture);\r\n\tSDL_DestroyRenderer(renderer);\r\n\tSDL_DestroyWindow(window);\r\n\tSDL_Quit();\r\n\r\n\texit(0);\r\n\r\n\treturn 0;\r\n}\r\n```\r\n\r\nOn the main.c thread I included the polling for mouse and keyboard events like so,\r\n\r\n```\r\n   while(1) {\r\n        /* Periodically call the lv_task handler.\r\n         * It could be done in a timer interrupt or an OS task too.*/\r\n        lv_task_handler();\r\n        usleep(1000);       /*Just to let the system breath*/\r\n\r\n\t    SDL_Event event;\r\n\t    while(SDL_PollEvent(&event)) {\r\n#if USE_MOUSE != 0\r\n            mouse_handler(&event);\r\n#endif\r\n\r\n#if USE_KEYBOARD\r\n            keyboard_handler(&event);\r\n#endif\r\n\t    }\r\n\r\n    }\r\n```\r\n\r\nThere is probably a better way to do this, but because I have zero experience with SDL I'm not sure of other solution may apply.\r\n\r\nCheers,\r\nMartin"},"comment":{"url":"https://api.github.com/repos/littlevgl/pc_simulator/issues/comments/414121075","html_url":"https://github.com/littlevgl/pc_simulator/issues/12#issuecomment-414121075","issue_url":"https://api.github.com/repos/littlevgl/pc_simulator/issues/12","id":414121075,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNDEyMTA3NQ==","user":{"login":"BrendanSimon","id":472245,"node_id":"MDQ6VXNlcjQ3MjI0NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/472245?v=4","gravatar_id":"","url":"https://api.github.com/users/BrendanSimon","html_url":"https://github.com/BrendanSimon","followers_url":"https://api.github.com/users/BrendanSimon/followers","following_url":"https://api.github.com/users/BrendanSimon/following{/other_user}","gists_url":"https://api.github.com/users/BrendanSimon/gists{/gist_id}","starred_url":"https://api.github.com/users/BrendanSimon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BrendanSimon/subscriptions","organizations_url":"https://api.github.com/users/BrendanSimon/orgs","repos_url":"https://api.github.com/users/BrendanSimon/repos","events_url":"https://api.github.com/users/BrendanSimon/events{/privacy}","received_events_url":"https://api.github.com/users/BrendanSimon/received_events","type":"User","site_admin":false},"created_at":"2018-08-19T11:26:35Z","updated_at":"2018-08-19T11:26:35Z","author_association":"NONE","body":"I've got the same issue.\r\nIs there a patch or a fork/branch that I can access to get a a working copy of the source to compile ??\r\nThanks :)"}}
{"actor":{"display_login":"BrendanSimon"}}