Hey.
Napisałem właśnie klase do prostej animacji poklatkowej tła w jednym z programów. Mam problem z funkcją która ma wczytać ścieżke do tektury z pliku tekstowego. To znaczy plik się wczytuję i przechodzi test ale przed zwróceniem wartości ( ścieżki do tekstury ) pojawia się 'segmentation fault'. Ciężko mi wnioskować przyczyny, może ktoś z was szybciej myśli :)? Tu jest część kodu w której implementuję wspomniany mechanizm:
#include "ani_background.h"
#include <iostream>
#include <allegro5/allegro.h>
#include <string>
AniBackground::~AniBackground()
{
delete spirite_path;
al_destroy_bitmap(texture);
}
std::string AniBackground::LoadPath()
{
std::string item;
file.open( "./.program.conf" );
if( file.good() )
std::cout << "Open program configuration file." << std::endl;
else{
std::cout << "Program configuration file opening error! " <<
"Please check if file '.program.conf' exists!" << std::endl;
exit(1);
}
int counter = 0;
while ( !file.eof() ){
file >> item;
counter ++;
}
file.close();
if ( spirite_path[0] == '.' && counter == 1 ){
std::cout << "Returning path to the program..." << std::endl;
return item;
}
else{
std::cout << "Path to spitite sheets needs to be executed by " <<
"'./'. File should contain one line of texture path!" << std::endl;
exit(1);
}
}
void AniBackground::Init(){
frameBox.fW = 352;
frameBox.fH = 240;
frameBox.fX = 0;
frameBox.fY = 0;
//*************************
fX = 0;
fY = 0;
cur_frame = 0;
max_frame = 26;
spirite_path = LoadPath().c_str();
texture = al_load_bitmap( spirite_path );
}
[...]
Output z działąnia (czy bardziej z niedziałania) programu:
Open program configuration file.
Segmentation fault (core dumped)