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++;
}
|
and
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void tile_creator::cb_click(Address, Address pw)
{
reference_to<tile_creator>(pw).move();
}
void tile_creator::move()
{
game->detach(tile);
int xbound = game->clicks*100;
Rectangle temp_rect(Point{xbound,600},90,90);
game->attach(temp_rect);
}
|
and the header file for tile_creator is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#ifndef TILE_GUARD
#define TILE_GUARD
#include "std_lib_facilities_4.h"
#include "GUI.h"
#include "Graph.h"
#include "Simple_window.h"
class Game_window;
class tile_creator{
public:
tile_creator(Game_window* a, int counter, string label);
Button tile;
string label;
private:
Game_window* game;
static void cb_click(Address, Address pw);
void move();
};
#endif
|
and the header for Game_window is this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#ifndef GAME_GUARD
#define GAME_GUARD
#include "std_lib_facilities_4.h"
#include "GUI.h"
#include "Graph.h"
#include "Simple_window.h"
class tile_creator;
struct Game_window : Graph_lib::Window{
Game_window(Point xy ,int w, int h, const string& title);
int clicks;
private:
string tile_value;
Button enter_diff;
In_box diff;
int difficulty;
int randint();
int tile_val;
void translate_value();
void make_tile();
void next();
static void cb_next(Address, Address pw);
int counter;
};
#endif
|
The window is of type Game_window, and then the button I am trying to attach/have the callback function is a member of type Button in tile_creator
and the error is:
*** glibc detected *** ./a.out: double free or corruption (out): 0x00007ffd0103 |
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.