mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 23:45:40 -07:00
[select][lvgl] Fix FixedVector size() returning 0 when using operator[] after init() (#11721)
This commit is contained in:
@@ -59,8 +59,8 @@ class LVGLSelect : public select::Select, public Component {
|
||||
const auto &opts = this->widget_->get_options();
|
||||
FixedVector<const char *> opt_ptrs;
|
||||
opt_ptrs.init(opts.size());
|
||||
for (size_t i = 0; i < opts.size(); i++) {
|
||||
opt_ptrs[i] = opts[i].c_str();
|
||||
for (const auto &opt : opts) {
|
||||
opt_ptrs.push_back(opt.c_str());
|
||||
}
|
||||
this->traits.set_options(opt_ptrs);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ void SelectTraits::set_options(const std::initializer_list<const char *> &option
|
||||
|
||||
void SelectTraits::set_options(const FixedVector<const char *> &options) {
|
||||
this->options_.init(options.size());
|
||||
for (size_t i = 0; i < options.size(); i++) {
|
||||
this->options_[i] = options[i];
|
||||
for (const auto &opt : options) {
|
||||
this->options_.push_back(opt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,6 +248,8 @@ template<typename T> class FixedVector {
|
||||
}
|
||||
|
||||
// Allocate capacity - can be called multiple times to reinit
|
||||
// IMPORTANT: After calling init(), you MUST use push_back() to add elements.
|
||||
// Direct assignment via operator[] does NOT update the size counter.
|
||||
void init(size_t n) {
|
||||
cleanup_();
|
||||
reset_();
|
||||
|
||||
Reference in New Issue
Block a user