So I thought maybe I would venture out a little from the lesson and try separating the code used to draw the map into its own header/source files just so I make sure I’m understanding how this is working. But when I created the files and called an instance in the main source file I’m getting an error on the header file constructor that just says “Segmentation Fault” with nothing else to help. I’m pretty sure I set the main function up correctly, here is the code:
#include “raylib.h”
#include “Level.h”
int main()
{
Level level;
level.createWindow();
while(!WindowShouldClose())
{
level.drawLevel();
}
CloseWindow();
}
#include “raylib.h”
class Level
{
public:
Level();
void createWindow();
void drawLevel();
private:
int windowWidth{1920};
int windowHeight{1080};
Texture2D map{LoadTexture("maps/spellbook_base_level.png")};
Vector2 mapPos{0.f, 0.f};
float mapScale{6.f};
};
#include “Level.h”
Level::Level()
{
}
void Level::createWindow()
{
InitWindow(windowWidth, windowHeight, "V2");
}
void Level::drawLevel()
{
BeginDrawing();
ClearBackground(BLACK);
DrawTextureEx(map, mapPos, 0.f, mapScale, WHITE);
}
Everything looks ok but I don’t know why I’m getting that Segmentation Fault. Can someone help and maybe explain what I’m doing wrong?
Thanks!