I encountered this problem in my project, not quite sure it is due to my mistake or my system/environment or IDL bug. I plotted charts on a widget_window, and draw a legend on it. It works fine if I don't touch the legend. However, if I move the legend window to another place. Then redraw the chart will cause an error saying:
% Unable to invoke method on NULL object reference: )>.
% Execution halted at: TESTAPP_EVENT 27 /home/MyProject/TestApp.pro
I extract the problematic portion of the code and put it here. Running the code, click on the [plot] button or [bar plot] will active a plotting function, and execute well if I don't move the legend. After moved the legend window, then click on the buttons will lead to an error.
My configure is IDL8.4, Debian Wheezy, Dell 64bits desktop. Here is the code and hope someone can give me some advice, thanks in advance.
;;;;;;;; code: TestApp.pro
PRO TestApp_Event, ev
WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
CASE uval OF
'goplot' : BEGIN
WIDGET_CONTROL, ev.TOP, GET_UVALUE=ptrwin
drawwin = *ptrwin
drawwin.select
drawwin.erase
xx = findgen(10);
cxx = cos(xx)
sxx = sin(xx)
p1 = PLOT(sxx, THICK=2, axis_style=2, Color='red', dim=[450,400], symbol='+', /current, name='sin')
p2 = PLOT(cxx, THICK=2, axis_style=2, Color='blue',/overplot, symbol='D', /current, name='cos')
yleg = max(cxx)
xleg = n_elements(xx)
leg = LEGEND(target=[p1, p2], /data, /auto_text_color, position=[xleg,yleg])
END
'gobarplot' : BEGIN
WIDGET_CONTROL, ev.TOP, GET_UVALUE=ptrwin
drawwin = *ptrwin
drawwin.select
drawwin.erase
xx = findgen(10);
cxx = cos(xx)
sxx = sin(xx)
p1 = BARPLOT(sxx, index=0, NBARS=2, fill_color='green', dim=[450,400], /current, name='sin')
p2 = BARPLOT(cxx, index=1, NBARS=2, fill_Color='orange',/overplot, /current, name='cos')
yleg = max(cxx)
xleg = n_elements(xx)
leg = LEGEND(target=[p1, p2], /data, /auto_text_color, position=[xleg,yleg])
END
'goclose' : WIDGET_CONTROL, ev.top, /DESTROY
ENDCASE
END
PRO TestApp
on_error, 2
DEVICE, RETAIN=2, DECOMPOSED=0
base = WIDGET_BASE(/COLUMN, XSIZE=500, YSIZE=550)
plotbase = widget_base(base, /row, xsize = 500, ysize=500)
drawWin0 = WIDGET_WINDOW(plotbase, UVALUE='DRAW0', UNAME='DRAW0', ysize = 500, xsize=500)
consbase = WIDGET_BASE(base, /ROW, XSIZE=500, YSIZE=30)
plotbutton = widget_button(consbase, VALUE='Plot', UVALUE='goplot')
barplotbutton = widget_button(consbase, VALUE='Bar Plot', UVALUE='gobarplot')
closebutton = widget_button(consbase, VALUE='Close', UVALUE='goclose')
WIDGET_CONTROL, base, /REALIZE
WIDGET_CONTROL, drawWin0, GET_VALUE = gDraw
WIDGET_CONTROL, base, set_uvalue=ptr_new(gDraw)
XMANAGER, 'TestApp', base, /NO_BLOCK
END
;;;;;;;; end of code: TestApp.pro
|