我void (*Draw)(WidgetVisualization *);
在 WidgetVisualization.h 中的类 WidgetVisualization 中有一个函数指针。
我有extern void GraphicVisualizationDraw(WidgetVisualization *w)
WidgetVisualization.cpp。
在 WidgetVisualization 的构造函数中,我分配Draw = GraphicVisualizationDraw;
.
这是 LCDGraphic.cpp 中的函数:
void GraphicVisualizationDraw(WidgetVisualization *widget) {
}
当我尝试将函数指针“Draw”分配给函数GraphicVisualizationDraw
时,我得到一个无效的写入。有什么线索吗?
这是 valgrind 的输出:
==8281== Invalid write of size 4
==8281== at 0x52D12C7: LCD::WidgetVisualization::WidgetVisualization(LCD::LCDCore*, std::string, Json::Value*, int, int, int) (WidgetVisualization.cpp:72)
==8281== by 0x530F0C3: LCD::LCDCore::BuildLayouts() (LCDCore.cpp:342)
==8281== by 0x5306A07: LCD::LCDControl::ConfigSetup() (LCDControl.cpp:213)
==8281== by 0x53062EC: LCD::LCDControl::Start() (LCDControl.cpp:57)
==8281== by 0x52D84E4: (anonymous namespace)::lcdcontrol_init(_VisPluginData*) (actor_lcdcontrol.cpp:115)
==8281== by 0x40645FA: visual_plugin_realize (lv_plugin.cpp:207)
==8281== by 0x405B1E7: visual_actor_realize (lv_actor.cpp:265)
==8281== by 0x404C02B: visual_bin_realize (lv_bin.c:108)
==8281== by 0x80507D1: main (lv-tool.cpp:378)
WidgetVisualization::WidgetVisualization(LCDCore *v, std::string n, Json::Value *section, int row, int col, int layer) : Widget(v, n, section, row, col, layer,
WIDGET_TYPE_VISUALIZATION | WIDGET_TYPE_RC | WIDGET_TYPE_SPECIAL) {
LCDError("widgetvisualization: layer: %d", layer_);
if(lcd_type_ == LCD_TEXT)
Draw = TextVisualizationDraw;
else if(lcd_type_ == LCD_GRAPHIC)
Draw = GraphicVisualizationDraw;// line 72
else
Draw = 0;