-
I'm having a weird problem with my program that I don't understand at all. Whenever I close the program I get this message in the output:
malloc: *** error for object 0x100c7ef68: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
I put in the breakpoint, but don't know how to read it really. When I run the program and it gets to that breakpoint, there doesn't seem to be anything wrong. But when I continue I get to a line in the "new" system file at the __builtin_operator_delete(__ptr);
line. It says Thread 1: signal SIGABRT
. I don't know how to begin to analyze this, has anyone every had this same issue?
-
I found the source of the error, it happens when I try to draw some text to the screen. Don't know why this causes the error, but I'll keep digging
-
Some quick questions that may help someone understand why your code might be having this problem:
- Are you using malloc?
- Are you using threads?
- Is the sf::Text or sf::Font in global scope?
Posting a complete and minimal example (https://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368) that still has this problem would also help greatly.
-
No to all. The sf::Font is a member of the class. The sf::Text is a local variable in the class method. Here is a simple version of the method that is causing the error:
void Game::_pauseGame() {
sf::Text pause, resume, options;
// Each of these cause the error
pause.setFont(_font);
resume.setFont(_font);
options.setFont(_font);
// Set string of the text variables
....
// Set the size and positioning of the text variables
....
// Trying to draw each of the text variables causes the error as well
_window.draw(pause);
_window.draw(resume);
_window.draw(options);
_window.draw(_pauseSword);
}
I also get the error when exiting the application, but I think that has something to do with the destruction of either the sf::Text or sf::Font variables.
Also, I didn't mention in my first post, but I'm using Xcode. It works fine in VS
-
No to all. The sf::Font is a member of the class. The sf::Text is a local variable in the class method.
Which class? The Game class? Is that class instanced in global scope?
If no to this, the above mentioned minimal and complete example will probably be required.
-
In main, a Game object is instanced
Game myGame;
The Game's constructor initializes all Game components and enters the main run loop
void Game::_init() {
// Initialize Media
_initializeMedia();
// Initialize System
_initializeSystem();
// Run the game
_run();
}
void Game::_run() {
sf::Clock frameClock;
while (_window.isOpen()) {
// Update animation timing
sf::Time frameTime = frameClock.restart();
_updateWindow();
_updateView();
if (_state == PLAY)
_updatePlayers(frameTime);
_draw();
}
}
There is a method within the main loop that runs the pause logic which prints the pause menu and other things (as shown in the code in my previous post). This is the method that is causing my issues
-
Didn't find a solution and walked away for a while. Just got back to it and still am having the same problem. It's clear that the error is coming from the sf::Font/sf::Text. Apparently this issue was relatively common in older versions of Xcode and was fixed with an update to SFML. I am using Xcode 10.1 so that can't be the problem. And I am quite certain the version of SFML I'm using is stable.
I made the Game's instances of sf::Text/sf::Font members of the class and now the error occurs after the return statement in main. So again, clearly that is the issue. Just don't know how to solve it
-
Well of course, it's now working with a new download of SFML. Surprise surprise