#include <stdio.h>
#include <stdlib.h>

#include <string.h>
#include <SDL/SDL.h>
#include <emscripten.h>
 
  
SDL_Surface *screen;

 
void renderloop(void) {
 SDL_Event event;
 SDL_Rect dst;
  SDL_LockSurface(screen);

  for(int n=0;n<1000;n++) {
    int x=random()%800;
    int y=random()%600;
    int pixel=random()*100000;
    int bpp = screen->format->BytesPerPixel;
    Uint8 *p = (Uint8 *)screen->pixels + y * screen->pitch + x * bpp;
    if((x>screen->w)||(y>screen->h)||(x<0)||(y<0)) return;
    *(Uint32 *)p = pixel;
  }
  
  SDL_UnlockSurface(screen);


  SDL_UpdateRect(screen, 0,0,0,0);

  while(SDL_PollEvent(&event))
   if(event.type==SDL_KEYDOWN) emscripten_cancel_main_loop();

}



 
int main(int argc, char *argv[]) {
 

  SDL_Init(SDL_INIT_VIDEO);
  
  screen=SDL_SetVideoMode(800,600,32,SDL_ANYFORMAT);
 
  printf("in loop\n"); 
  emscripten_set_main_loop(renderloop,0,1);
  printf("out loop\n");
  return 0;
}

ok, you run it and press any key to exit the loop. When the loop stops it 
doesn't call "printf("out loop\n");" :(

On Sunday, August 26, 2018 at 12:59:49 PM UTC-5, Alon Zakai wrote:
>
> I don't think that should matter (it just affects what happens in the 
> initial call to set the main loop). But let us know if you find a testcase 
> showing that, perhaps there's a bug.
>
> On Sun, Aug 26, 2018 at 8:15 AM sigflup synasloble <[email protected] 
> <javascript:>> wrote:
>
>> Maybe it's because I have the simulate infinite loop argument on
>>
>>
>> On Sunday, August 26, 2018 at 8:49:00 AM UTC-5, Alon Zakai wrote:
>>>
>>> This should work, and looks like we have a passing test for it, 
>>> browser.test_emscripten_main_loop, so I think there might be something more 
>>> going on in your application. Can you provide a testcase showing the issue?
>>>
>>> On Fri, Aug 24, 2018 at 5:36 PM sigflup synasloble <[email protected]> 
>>> wrote:
>>>
>>>> I want to exit main loop by calling cancel_main_loop inside of the 
>>>> loop. 
>>>>
>>>> When I do this my program hangs :(
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "emscripten-discuss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to