错误消息是:
fary tail.exe中的0x00007ffca9067788在0x00007ffca9067788中生产。Exe:Microsoft C ++例外:_com_error在存储器位置0x00000000000000F86C0FED6060
一个:
函数
,ID3D11DEVICE1 :: CreatePixelShader:参数不正确
明显只有在我使用函数sdl_geterror()检查纹理是否已加载时,特别是这些代码行:{
SDL_GetError()
if(SDL_RenderTexture(renderer, fairy, NULL, NULL)
这里是更好理解的完整代码:
SDL_Log("IMG Error: %s", SDL_GetError());
}
班路仅使用错误检查以获取错误,意味着当某些内容未正确返回时。
//Header file mygame.h
#pragma once
#include <iostream>
#include "SDL3/SDL.h"
#include "SDL_image.h"
class Game
{
public:
Game();
~Game();
void init(const char*, int xpos, int ypos, int width, int height, bool fullscreen);
void handle_events();
void update();
void render();
void clean();
bool running();
private:
bool is_running = NULL;
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
//Source File for the function definitions of the above header file mygame.cpp
#include "mygame.h"
SDL_Texture* fairy = NULL;
Game::Game() {}
Game::~Game() {}
//Initialization function
void Game::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
{
int flags = 0;
if (fullscreen)
{
flags = SDL_WINDOW_FULLSCREEN;
}
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
std::cout << "Error: Couldn't initialize SDL!" << std::endl;
is_running = false;
return;
}
//Creating Window
window = SDL_CreateWindow(title, width, height, flags);
if(window)
{
std::cout << "Window Created!";
}
//Creating Renderer
renderer = SDL_CreateRenderer(window, NULL);
if(renderer)
{
std::cout << "Renderer Created" << std::endl;
}
is_running = true;
fairy = IMG_LoadTexture(renderer, "assets/hadita.png");
}
void Game::handle_events()
{
SDL_Event event;
SDL_PollEvent(&event);
switch(event.type)
{
case SDL_EVENT_QUIT:
is_running = false;
default:
break;
}
}
void Game::update(){}
void Game::render()
{
SDL_RenderClear(renderer);
if(SDL_RenderTexture(renderer, fairy))
{
SDL_Log("IMG Render Error: %s", SDL_GetError());
}
SDL_RenderPresent(renderer);
}
void Game:clean()
{
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_DestroyTexture(fairy);
SDL_Quit();
std::cout << "Game cleaned";
}
bool Game::running()
{
return is_running;
}
//Now finally the main.cpp file where the game loop is
#include "mygame.h"
Game* game = nullptr;
int main(int argc, const char* argv[])
{
game = new Game();
game->init("A Fairy Tale", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, false);
while (game->running())
{
game->handle_events();
game->update();
game->render();
}
game -> clean();
return 0;
}
如果正确返回为什么会出现错误,请这样想。
if (!SDL_RenderTexture(renderer, fairy)) { }
在此时给您最新的错误。