-
Notifications
You must be signed in to change notification settings - Fork 62
Open
Description
So I compiled this on macos. And it immediately crashed after clicking to start a game.
However after some debugging I found the issue is your getStrokeText and getLevelText functions return a pointer to a std::string that is destructed in the function. A quick hack/fix for this, was to define them as globals so they stay in memory. Then the game works also on my macbook on catelina ;)
Here's the patch:
//reserve string in memory that does not get deleted
//as were returning char* from this!
std::string stroke_text="";
std::string level_text="";
const char* getStrokeText()
{
stroke_text="";
int biggestStroke = 0;
if (balls[1].getStrokes() > balls[0].getStrokes())
{
biggestStroke = balls[1].getStrokes();
}
else
{
biggestStroke = balls[0].getStrokes();
}
std::string s = std::to_string(biggestStroke);
stroke_text = "STROKES: " + s;
return stroke_text.c_str();
}
const char* getLevelText(int side)
{
int tempLevel = (level + 1)*2 - 1;
if (side == 1)
{
tempLevel++;
}
std::string s = std::to_string(tempLevel);
level_text = "HOLE: " + s;
return level_text.c_str();
}
Another smaller issue was I was always getting a ttf error because the check did not work correctly.
This I patched as follows:
bool init()
{
if (SDL_Init(SDL_INIT_VIDEO) > 0)
std::cout << "HEY.. SDL_Init HAS FAILED. SDL_ERROR: " << SDL_GetError() << std::endl;
if (!(IMG_Init(IMG_INIT_PNG)))
std::cout << "IMG_init has failed. Error: " << SDL_GetError() << std::endl;
if (TTF_Init()==-1){
std::cout << "TTF_init has failed. Error: "<< TTF_GetError() << std::endl;
}
std::cout<<"Opening audio now!"<<std::endl;
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
return true;
}
Ideally however you could better return a std::string or a smart pointer instead.
Now everything works except the sounds are not playing. But I do see its a nice game. Well done in 2 days ;).
Metadata
Metadata
Assignees
Labels
No labels
