我正在制作一个小的“复古风格”2D平台游戏与SDL在C++。我认为,保持游戏的低分辨率,同时允许具有不同大小监视器的人拉伸游戏窗口以适应他们的设置,最好的方法是将所有内容呈现为低分辨率的纹理,然后将该纹理呈现到整个窗口(由用户设置窗口大小/分辨率)。
当我运行这个设置时,游戏完全按照它应该的方式工作,并且呈现得很好(无论是在全屏模式还是窗口模式)。然而,当我使用SDL_DestroyTexture()释放我的低分辨率渲染目标纹理时,控制台会发出"ERROR:无效纹理“。我已经确认这是使用调试器发生错误的地方。下面是创建、使用和破坏纹理的相关代码。为什么纹理突然失效时,我可以正常使用它,否则?
// SDL is initialized
// "proxy" is the texture used for render-to-texture
// it is set to the "logical" low resolution (lxres, lyres) (usually 320x240)
// renderer is an SDL_Renderer* that initializes with no problems
SDL_Texture* proxy = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET, lxres, lyres);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
// game runs fine
while (!quit) {
SDL_SetRenderTarget(renderer, proxy);
render();
SDL_SetRenderTarget(renderer, nullptr);
// stretch the low resolution texture onto the at-least-as-high resolution
// renderer (usually 640x480)
SDL_RenderCopy(renderer, proxy, nullptr, nullptr);
SDL_RenderPresent(renderer);
SDL_RenderClear(renderer);
updateLogic();
}
// Time to quit
SDL_SetRenderTarget(renderer, nullptr);
if (proxy != nullptr)
SDL_DestroyTexture(proxy); // "ERROR: Invalid texture"
// Clean up other resources
// close SDL发布于 2014-09-03 11:25:06
当我销毁渲染器之前破坏贴图的纹理时,这种类型的错误已经触碰到了我。
https://stackoverflow.com/questions/25569985
复制相似问题