First and foremost, I'm in the process of learning C++ & SDL2 coming from a C# background. I'm getting an unhandled exception which should be contained within a try/catch but the line of code should from other examples should execute successfully. The exception is happening at the SDL_RenderCopy()
function.
Any help/direction would be most appreciated in my long journey of C++!
Gameboard.h
#ifndef GAMEBOARD_H
#define GAMEBOARD_H
#include "GenericEntity.h"
#include "GameboardParameters.h"
#include "Piece.h"
#include <iostream>
// Board witdh & height in pieces
#define BOARD_WIDTH 6
#define BOARD_HEIGHT 11
// Piece width & height in pixels
#define PIECE_WIDTH 32
#define PIECE_HEIGHT 32
// Define next pieces buffer
#define NEXT_PIECES 255
class Gameboard : public GenericEntity {
public:
Gameboard(SDL_Renderer *renderer, GameboardParameters parms);
~Gameboard();
void Render(float delta);
void Update(float delta);
void CreateLevel();
public:
float FALL_SPEED = 50;
Piece p1_pieces[BOARD_WIDTH][BOARD_HEIGHT];
Piece next_pieces[NEXT_PIECES];
private:
SDL_Texture *sdlTextureBackground;
SDL_Texture *sdlTextureBackgroundGrid;
SDL_Texture *texTarget;
};
#endif //GAMEBOARD_H
Gameboard.cpp
Gameboard::Gameboard(SDL_Renderer *renderer, GameboardParameters parms) : GenericEntity(renderer) {
SDL_Surface *sdlSurfaceBackground = IMG_Load("resources/backgrounds/SC_S_01.BMP");
sdlTextureBackground = SDL_CreateTextureFromSurface(renderer, sdlSurfaceBackground);
SDL_FreeSurface(sdlSurfaceBackground);
SDL_Surface *sdlSurfaceBackgroundGrid = IMG_Load("resources/backgrounds/GRID-768X1408.PNG");
sdlTextureBackgroundGrid = SDL_CreateTextureFromSurface(renderer, sdlSurfaceBackgroundGrid);
SDL_FreeSurface(sdlSurfaceBackgroundGrid);
}
...
void Gameboard::Render(float delta) {
// Clear screen
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
// Render background
SDL_RenderCopy(renderer, sdlTextureBackground, NULL, NULL);
}