简体   繁体   中英

C - SDL2 window crash from simple animation loop

I am currently learning to use SDL2 in C and encountered a problem from which I couldn't find a solution so far

I am trying to run a simple 2 frames animation loop in the middle of the screen, but after a seemingly set amount of loops the window stops responding

while (1)
{
  SDL_RenderClear(window->renderer);
  test->o_update(sheet, test);
  SDL_RenderCopy(window->renderer, sheet->texture, &test->frame, &test->pos);
  SDL_RenderPresent(window->renderer);
  SDL_Delay(16);
}

The update function updates the coordinates on the sheet of the SDL_rect named "frame" in the test structure, so that it switches to the next frame every 30 frame. Every frame I SDL_RenderCopy, and SDL_RenderPresent to update the screen. Is there something blatantly wrong in my way of doing things ?

问题出在缺少对SDL事件的等待/轮询,在这种情况下,该过程最终停止响应。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM