【发布时间】:2014-03-18 11:30:30
【问题描述】:
我最近一直在写一些 SDL2,今天我重写了我的代码的基础,使其更加结构化和更易于使用。
我遇到的问题是在尝试对 sprite 表面进行 blit 时,它给了我 SDL 错误 Surfaces must not be locked during blit,这似乎是合理的,所以我在 SDL_BlitSurface 之前的 blit 函数的开头添加了 SDL_UnlockSurface 但仍然返回同样的错误。
因为我在文档中看到SDL_UnlockSurface 是一个空洞,所以我不知道它是否成功,但由于它不是多线程的,所以在我进行 blitting 时没有任何东西可以强制锁定它(而且它只是在无论如何都要启动应用程序)。
这是 blit 函数
bool Sprite::blit(SDL_Surface* targetSurface){
SDL_UnlockSurface(this->surface);
int success = SDL_BlitSurface( this->surface, NULL, targetSurface, NULL );
if ( success != 0){
printf( "Unable to blit surface! SDL Error: %s\n"m SDL_GetError() );
return false;
}
return true;
}
提前致谢!
【问题讨论】: