I'm using SDL to read paths from a text document. This works fine, and I have a list of all the textures loaded displaying on the side just fine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
bool load_textures_from_file()
{
std::ifstream file;
file.open("file.txt");
if(!file.is_open())
{
std::cout << "No file.txt detected. Please include this. Closing soon.";
SDL_Delay(5000);
return false;
}
std::string text;
while(getline(file,text))
{
tex_list.push_back(loadTexture(text.c_str()));
}
return true;
}
|
That's how it loads it, the tex_list is declared:<code> std::vector<SDL_Texture*> tex_list;</code>
This code is working fine I believe, since I am using it to display all the loaded textures already. My issue stems from the terrain.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class terrain
{
public:
int x;
int y;
int w;
int h;
SDL_Texture * tex;
terrain(int x_, int y_, int w_, int h_, SDL_Texture*texx)
{
x = x_;
y = y_;
w = w_;
h = h_;
tex = texx;
}
};
|
That's the definition of a piece of terrain
<code> set_pieces.push_back(terrain(100,100,100,100,tex_list[0]));</code>
This is creating a test piece of terrain.
The actual issue loop in question:
1 2 3 4 5 6 7 8
|
for(int i = 0; i < set_pieces.size(); i++)
{
if(!g_cam.in_range(set_pieces[i].x,set_pieces[i].y))
{
continue;
}
coords rend = g_cam.get_coords(set_pieces[i].x,set_pieces[i].y);
renSpec(mainren,set_pieces[i].tex,set_pieces[i].w,set_pieces[i].h, rend.x, rend.y);
|
in_range is working as expected, and coords are giving good x/y values. I've tried mainren is working (There is another piece rendering to it so yeah), however I've tried replacing set_pieces[i].tex with my load texture function and it still fails to work. In the debugger, I get a SIGSEGV however the program doesn't crash if I'm not in the debugger.
1 2 3 4 5 6 7 8 9
|
void renSpec(SDL_Renderer* ren,SDL_Texture* texs, int w, int h,int x, int y)
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
SDL_RenderCopy(ren,texs, NULL,&rect);
}
|
If I run the program normally, the image doesn't show up, but it doesn't crash.
Sorry for the long list of stuff but I'm trying to give all the pieces that may be relevant to the issue.