Skip to main content

Posts

Featured

C++ : a nasty bug

It took me 2 days to figure out this bug in C++. The context I use ncurses and I want to manage several windows. I created a class (Window) with all the methods I need. class Window { private: WINDOW *win; ... public: ... } No issue here. To store my objects, I used a vector of pointers: std::vector<Window*> Windows; The bug I want to create 2 windows, so I did the following: Window *A = new Window(...); // Instantiate the class Window, implicitely calling the constructor Windows.push_back(*A); // Adding object A to the vectors Window *B = new Window(...); // New instantiation Windows.push_back(*B); // Adding object B to the vectors The bug was here: when I pushed back the second object (B), the memory manager decided to reallocate the vectors, because vectors must be contiguous. Doing so implicitely called the destructor of the first object; the window A disappeared. Possible solutions Reserve memory for the vectors Windo...

Latest posts

MIDI dump of Yamaha TX816

Ubuntu 24.04: Shortcuts in terminal

Quickly sorting resistors

Fake voltage regulators

My journey with ATTiny4313 (part 6)

My journey with ATTiny4313 (part 5)

My journey with ATTiny4313 (part 4)

My journey with ATTiny4313 (part 3)

Fixing a broken key on Yamaha QX1

Fixing a Roland FP-8 Digital Piano