Witajcie , mam problem , jestem początkującym samoukiem w programowaniu, obecnie czytam książkę o SDL. Staram się postępować jak autor jednakże gdzieś chyba się pomyliłem i za chiny nie mogę dojść gdzie ;/
Visual wywala mi to :
First-chance exception at 0x00386CFE in Projekt1.exe: 0xC0000005: Access violation writing location 0x00000000.
Mógłbym prosic o radę?
(Nagłówek)
#include "SDL.h"
#ifndef __Game__
#define __Game__
class Game
{
public:
Game();
~Game();
bool init(const char* title, int xpos, int ypos, int width, int
height, int flags);
void render();
void update();
void handleEvents();
void clean();
bool running() { return m_bRunning; }
private:
SDL_Window* m_pWindow;
SDL_Renderer* m_pRenderer;
bool m_bRunning;
};
#endif
(Plik źródłowy)
#include <iostream>
#include <SDL.h>
#include "Nagłówek.h"
Game * g_game = 0;
int main(int argc, char* argv[])
{
g_game->init("Chapter 1", 100, 100, 640, 480, 0);
while (g_game->running())
{
g_game->handleEvents();
g_game->render();
}
g_game->clean();
return 0;
}
bool Game::init(const char* title, int xpos, int ypos, int width,
int height, int flags)
{
// attempt to initialize SDL
if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
std::cout << "SDL init success\n";
// init the window
m_pWindow = SDL_CreateWindow(title, xpos, ypos,width, height, flags);
if (m_pWindow != 0) // window init success
{
std::cout << "window creation success\n";
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
if (m_pRenderer != 0) // renderer init success
{
std::cout << "renderer creation success\n";
SDL_SetRenderDrawColor(m_pRenderer,
255, 255, 255, 255);
}
else
{
std::cout << "renderer init fail\n";
return false; // renderer init fail
}
}
else
{
std::cout << "window init fail\n";
return false; // window init fail
}
}
else
{
std::cout << "SDL init fail\n";
return false; // SDL init fail
}
std::cout << "init success\n";
m_bRunning = true; // everything inited successfully,start the main loop
return true;
}
void Game::render()
{
SDL_RenderClear(m_pRenderer); // clear the renderer tothe draw color
SDL_RenderPresent(m_pRenderer); // draw to the screen
}
void Game::clean()
{
std::cout << "cleaning game\n";
SDL_DestroyWindow(m_pWindow);
SDL_DestroyRenderer(m_pRenderer);
SDL_Quit();
}
void Game::handleEvents()
{
SDL_Event event;
if (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
m_bRunning = false;
break;
default:
break;
}
}
}