Page MenuHome

UI: support 'activate_init' for popups which refresh
Closed, ResolvedPublicTO DO

Description

Currently 'activate_init' layout property doesn't work for popups which run their draw function multiple times once opened.


System Information
Operating system: Linux-5.3.7-arch1-1-ARCH-x86_64-with-arch 64 Bits
Graphics card: GeForce GTX 660M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 435.21

Blender Version
Broken versions:
2.81 (sub 15), branch: master, commit date: 2019-10-24 19:00, hash: rB892c3891ed0b
2.82 (sub 1), branch: master, commit date: 2019-10-24 19:11, hash: rB2a3b5dc73038

Short description of error
Setting the activate_init property of a UILayout causes weird behavior and often causes the blender ui to freeze. I'm including a test addon that utilizes activate_init in a panel, a popup, and an item within a UIList in a popup. Both the popup and the UIList item cause the whole ui to freeze after interacting with them, while the panel just isn't affected at all. The weird behavior only seems to happen after you press enter or otherwise finish interacting with the auto-activated field; everything acts like you would expect until you finish and find the UI is non-responsive.

The panel is named Test Panel and located in the Object tab of the Properties Editor.
The popup can be called by pressing ALT-T
The UIList can be called by pressing CTRL-T

Exact steps for others to reproduce the error
Install and activate the test addon.
Press one of the hotkeys.
Press enter to finish editing the auto activated field.
Try to pan the 3D View using the middle mouse button.

Event Timeline

JPG (joules) added a subscriber: JPG (joules).EditedOct 26 2019, 9:25 AM

I can confirm this freezes the UI.

I came across a crash however trying to capture an event.
Regardless of activate_init enabled or not. Tried to capture an event (i.e {'ESC'}) with a modal() handler added with invoke() however blender will crash on modal(). Could be related or a case of don't do that with popups.

Jacques Lucke (JacquesLucke) changed the task status from Needs Triage to Needs Information from User.Tue, Jan 21, 11:19 AM

I can confirm that this is freezing the UI as well.
It does not crash or is completely unresponsive though.

The File Close Dialog is still working as usual (when you try to close Blender). So it looks like there is an issue with the event handling somewhere.

@Ryan Inch (Imaginer) Can you explain what the test variable is supposed to do? While I haven't used the activate_init feature myself yet, your use of the test variable seems weird.

Interestingly, when I remove it, I actually get a crash.

==473==ERROR: AddressSanitizer: heap-use-after-free on address 0x6190004295c8 at pc 0x55f3950700c2 bp 0x7ffd84a25460 sp 0x7ffd84a25450
READ of size 4 at 0x6190004295c8 thread T0
    #0 0x55f3950700c1 in UI_block_active_only_flagged_buttons /home/jacques/blender-git/blender/source/blender/editors/interface/interface.c:895
    #1 0x55f391da0fdf in wm_operator_ui_create /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm_operators.c:1470
    #2 0x55f39522d70b in ui_popup_block_refresh /home/jacques/blender-git/blender/source/blender/editors/interface/interface_region_popup.c:573
    #3 0x55f39522b038 in ui_block_region_refresh /home/jacques/blender-git/blender/source/blender/editors/interface/interface_region_popup.c:401
    #4 0x55f391d0a2da in wm_draw_window_offscreen /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm_draw.c:656
    #5 0x55f391d0b106 in wm_draw_window /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm_draw.c:770
    #6 0x55f391d0c4d8 in wm_draw_update /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm_draw.c:952
    #7 0x55f391cfd168 in WM_main /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm.c:423
    #8 0x55f390f7f6ed in main /home/jacques/blender-git/blender/source/creator/creator.c:518
    #9 0x7fa8fe12e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2)
    #10 0x55f390f7ea2d in _start (/home/jacques/blender-git/build_linux/bin/blender+0x30ceaa2d)

0x6190004295c8 is located 72 bytes inside of 1152-byte region [0x619000429580,0x619000429a00)
freed by thread T0 here:
    #0 0x7fa8fea306ef in __interceptor_free (/lib/x86_64-linux-gnu/libasan.so.5+0x10d6ef)
    #1 0x55f3a8884fa1 in rem_memblock /home/jacques/blender-git/blender/intern/guardedalloc/intern/mallocn_guarded_impl.c:1097
    #2 0x55f3a8883d95 in MEM_guarded_freeN /home/jacques/blender-git/blender/intern/guardedalloc/intern/mallocn_guarded_impl.c:983
    #3 0x55f39508a476 in ui_but_free /home/jacques/blender-git/blender/source/blender/editors/interface/interface.c:3216
    #4 0x55f39506fef7 in UI_but_active_only /home/jacques/blender-git/blender/source/blender/editors/interface/interface.c:877
    #5 0x55f39507004d in UI_block_active_only_flagged_buttons /home/jacques/blender-git/blender/source/blender/editors/interface/interface.c:890
    #6 0x55f391da0fdf in wm_operator_ui_create /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm_operators.c:1470
    #7 0x55f39522d70b in ui_popup_block_refresh /home/jacques/blender-git/blender/source/blender/editors/interface/interface_region_popup.c:573
    #8 0x55f39522b038 in ui_block_region_refresh /home/jacques/blender-git/blender/source/blender/editors/interface/interface_region_popup.c:401
    #9 0x55f391d0a2da in wm_draw_window_offscreen /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm_draw.c:656
    #10 0x55f391d0b106 in wm_draw_window /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm_draw.c:770
    #11 0x55f391d0c4d8 in wm_draw_update /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm_draw.c:952
    #12 0x55f391cfd168 in WM_main /home/jacques/blender-git/blender/source/blender/windowmanager/intern/wm.c:423
    #13 0x55f390f7f6ed in main /home/jacques/blender-git/blender/source/creator/creator.c:518
    #14 0x7fa8fe12e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2)

previously allocated by thread T0 here:
    #0 0x7fa8fea30ce6 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dce6)
    #1 0x55f3a8881f68 in MEM_guarded_callocN /home/jacques/blender-git/blender/intern/guardedalloc/intern/mallocn_guarded_impl.c:613
    #2 0x55f39508fd9d in ui_but_alloc /home/jacques/blender-git/blender/source/blender/editors/interface/interface.c:3671
    #3 0x55f395090210 in ui_def_but /home/jacques/blender-git/blender/source/blender/editors/interface/interface.c:3727
    #4 0x55f39509707b in ui_def_but_rna /home/jacques/blender-git/blender/source/blender/editors/interface/interface.c:4270
    #5 0x55f395099bab in uiDefButR_prop /home/jacques/blender-git/blender/source/blender/editors/interface/interface.c:4869
    #6 0x55f395299288 in uiDefAutoButR /home/jacques/blender-git/blender/source/blender/editors/interface/interface_utils.c:225
    #7 0x55f3951965c9 in ui_item_with_label /home/jacques/blender-git/blender/source/blender/editors/interface/interface_layout.c:1048
    #8 0x55f3951a01f1 in uiItemFullR /home/jacques/blender-git/blender/source/blender/editors/interface/interface_layout.c:2166
    #9 0x55f39378310d in rna_uiItemR /home/jacques/blender-git/blender/source/blender/makesrna/intern/rna_ui_api.c:136
    #10 0x55f393790904 in UILayout_prop_call /home/jacques/blender-git/build_linux/source/blender/makesrna/intern/rna_ui_gen.c:1794
    #11 0x55f39303fd78 in RNA_function_call /home/jacques/blender-git/blender/source/blender/makesrna/intern/rna_access.c:7558
    #12 0x55f3939326b7 in pyrna_func_call /home/jacques/blender-git/blender/source/blender/python/intern/bpy_rna.c:6146
    #13 0x55f3a9e89163 in _PyObject_FastCallKeywords Objects/call.c:199

@Jacques Lucke (JacquesLucke) I'm a little foggy on the details, but if I recall correctly I used test to make sure activate_init was only set once (so ui redraws wouldn't set it multiple times) to try and improve the result (could have been to avoid the crash). Another reason you'd want something like this is to allow activate_init to only be set in certain situations. I put this demonstration addon together quickly and didn't use blender's bool properties or annotation syntax, but I just tested and it performs the same.

Thanks for taking a look at this. :)

Dalai Felinto (dfelinto) changed the task status from Needs Information from User to Needs Triage.Thu, Feb 6, 3:00 PM
Campbell Barton (campbellbarton) changed the subtype of this task from "Report" to "To Do".Wed, Feb 12, 12:16 PM
Campbell Barton (campbellbarton) renamed this task from Using Activate Init in an Addon Causes the Blender UI to Freeze to UI: support 'activate_init' for popups which refresh.Wed, Feb 12, 12:20 PM
Campbell Barton (campbellbarton) changed the task status from Needs Triage to Confirmed.
Campbell Barton (campbellbarton) updated the task description. (Show Details)