I tried posting this question under the course directly, but got no response, so figured I would ask here.
So I thought maybe I would venture out a little from a lesson on Header Files and Constructors and try separating the code used to draw a 2D map into its own header/source files, just so I make sure I’m understanding how creating separate source files and creating header files works. But when I created the files and called an instance of my source file 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();
}
#pragma once
#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!