gpt4 book ai didi

c++ - SDL2 CreateRenderer 抛出无效窗口错误

转载 作者:太空狗 更新时间:2023-10-29 21:00:09 25 4
gpt4 key购买 nike

我目前的代码如下:

#include <iostream>
#include "SDL.h"
#include "SDL_image.h"

int main(int argc, char **argv) {
if (SDL_Init(SDL_INIT_EVERYTHING != 0)) {
std::cout << "SDL_Init() Error: " << SDL_GetError() << std::endl;
std::cin.get();
return 1;
}

SDL_Window *win = SDL_CreateWindow("RandomSDL2", 100, 100, 1280, 720, SDL_WINDOW_SHOWN);
if (win = nullptr) {
std::cout << "SDL_CreateWindow() Error: " << SDL_GetError() << std::endl;
std::cin.get();
return 1;
}

SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (ren == nullptr) {
std::cout << "SDL_CreateRenderer() Error: " << SDL_GetError() << std::endl;
std::cin.get();
return 1;
}

SDL_Surface *img = IMG_Load("res/test.png");
if (img == nullptr) {
std::cout << "IMG_Load() Error: " << IMG_GetError() << std::endl;
std::cin.get();
return 1;
}

SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, img);
SDL_FreeSurface(img);
if (tex == nullptr) {
std::cout << "SDL_CreateTextureFromSurface() Error: " << SDL_GetError << std::endl;
std::cin.get();
}

SDL_RenderClear(ren);
SDL_RenderCopy(ren, tex, NULL, NULL);
SDL_RenderPresent(ren);

SDL_Delay(2000);

SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);

SDL_Quit();

return 0;
}

似乎 CreateRenderer 函数抛出无效窗口错误,我不确定为什么,我目前正在关注 this教程,除了分辨率和 SDL_image 的使用之外,我已经将代码复制到 T,SDL_image 不应该真正影响这个阶段渲染器的创建,我也尝试了教程中指定的分辨率,看起来仍然会抛出相同的错误。

有没有人对这个问题有任何见解?

最佳答案

if (win = nullptr) {
^ assignment, probably wanted ==

不要将 win 设置为 nullptr,它可能不会是 nullptr

关于c++ - SDL2 CreateRenderer 抛出无效窗口错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22903466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com