带有 C++ 和 SDL2 的小型 CLion 项目崩溃,退出代码为 468

Small CLion project with C++ and SDL2 crashing with exit code 468

提问人:fortwoone 提问时间:11/7/2023 更新时间:11/7/2023 访问量:27

问:

所以我最近一直在玩 CLion,并想建立一个示例项目,因为我在空闲时间做游戏开发,但是一旦我设法让 CMake 文件与 SDL2 一起使用,我最终几乎每次尝试运行程序时都会点击退出代码 468。代码如下:

main.cpp :

#include <iostream>
#include "type_test.h"
#include "sdl_include.h"
using namespace std;


int main(int argc, char *argv[]){
    cout << "Hello, World!" << endl;
    Bidule bidule = Bidule(5, 'e');
    cout << bidule.get_truc() << endl;
    cout << bidule.get_machin() << endl;
    if (SDL_Init(SDL_INIT_EVERYTHING)<0){
        cout << "Failed to initialise SDL. Error cause : " << SDL_GetError() << endl;
        return 1;
    }
    SDL_Window* win = SDL_CreateWindow("Titre", WIN_NOANCHOR, WIN_NOANCHOR, 160, 144, SDL_WINDOW_SHOWN);
    if (win == nullptr){
        cout << "Failed to create the window. Error cause : " << SDL_GetError() << endl;
        return 1;
    }
    SDL_Renderer* renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED| SDL_RENDERER_PRESENTVSYNC);
    if (renderer == nullptr){
        cout << "Failed to create a renderer for the window. Error cause : " << SDL_GetError() << endl;
        return 1;
    }
    SDL_SetRenderDrawColor(renderer, 0, 0, 0xFF, 0xFF);
    int init_img = IMG_INIT_PNG;
    if (!(IMG_Init(init_img) & init_img)){
        cout << "Failed to initialise SDL_image. Error cause : " << IMG_GetError() << endl;
    }
    bool running = true;
    SDL_Event evt;

    while (running){
        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);
        while (SDL_PollEvent(&evt)) {
            if (evt.type == SDL_QUIT) {
                running = false;
                break;
            }
        }
    }
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(win);
    SDL_Quit();
    return 0;
}

type_test.h :

#ifndef TEST_CLION_TYPE_TEST_H
#define TEST_CLION_TYPE_TEST_H

class Bidule{
    public:
        Bidule(short truc, char machin);
        short get_truc();
        char get_machin();
    private:
        short truc;
        char machin;
};

#endif //TEST_CLION_TYPE_TEST_H

type_test.cpp:

#include "type_test.h"

Bidule::Bidule(short truc, char machin){
    this->truc = truc;
    this->machin = machin;
}

short Bidule::get_truc(){
    return this->truc;
}

char Bidule::get_machin(){
    return this->machin;
}

sdl_include.h :

#ifndef TEST_CLION_SDL_INCLUDE_H
#define TEST_CLION_SDL_INCLUDE_H
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#define WIN_NOANCHOR SDL_WINDOWPOS_UNDEFINED

#endif //TEST_CLION_SDL_INCLUDE_H

有谁知道我搞砸了什么或这个退出代码是什么意思?(更准确地说,在我尝试将 SDL 添加到项目中之前,Bidule 类运行良好)

我希望程序能够正常运行,因为它编译和链接得很好,但它甚至没有给我一个错误,只是在没有运行任何代码的情况下退出......

C++ SDL-2 CLION)

评论

0赞 HolyBlackCat 11/7/2023
调试器显示什么?如果在资源管理器中双击 exe,是否会得到更好的错误消息?
0赞 fortwoone 11/7/2023
CLion 的调试器在这里没有任何帮助,我得到了完全相同的代码,而 main 函数似乎甚至没有执行。我只是尝试从资源管理器运行可执行文件,但没有任何反应,终端窗口随后立即打开和关闭,甚至没有打印任何内容......
0赞 fortwoone 11/7/2023
当我尝试从终端本身运行程序时,根本没有打印任何内容,甚至没有退出代码

答: 暂无答案