I'm fairly new to C++ and i've just recently gotten an error I'm not very familiar with. I'm working on a project that uses fltk and my professor created a kind of simplified version of fltk for us to work with.
I've managed to create an object of a class that extends a window, and then within that class call another class multiple times that will create multiple buttons and attach them to the original window.
The problem comes in when I try to implement a callback function that will move the button that is clicked on the original window.
Here is where I've found/think that the problem is at.
1 2 3 4 5
void Game_window::make_tile(){
int xpoint = counter*100;
new tile_creator(this, xpoint, tile_value);
counter++;
}
with a long backtrace/memory map that I could provide if needed, but I feel that it'd just clutter the post.
I'm just trying to get a better idea of what exactly is going on with the code, and if I could be pointed in the right direction on where to continue with it.
The error is trying to tell you that a routine in the GNU C runtime library (AKA glibc) detected a double-free (i.e., you deleted memory more than once) or heap-memory corruption (i.e., you smashed some heap memory) at or around the address it gave you.
The first thing you should check is object ownership. Who owns who, and when? Your use of raw pointers makes this opaque; you should keep careful track of that. In modern C++ you can (and should) avoid most problems like this by using the appropriate smart pointer to explicitly enforce ownership semantics for you.
The line new tile_creator(this, xpoint, tile_value); appears to leak memory. Even if it does not due to code in the constructor, the statement is highly dubious.
You didn't specify when your code crashes, but I would suggest you check to make sure your callback's dynamic environment remains valid until it is deregistered.
There is not enough context here to diagnose. Where do you register the callback? What is reference_to<> and Address?