I try to add an notifier to the scene,but it crash immediatly.
here is my code in dll:
void BLI_addtail(ListBase*listbase, void*vlink)
{
Link*link =(Link*) vlink;
if (link == NULL) return;
link->next = NULL;
link->prev = (Link*)listbase->last;
if (listbase->last)
{
((Link*)listbase->last)->next = link;}
if (listbase->first == NULL)
{
listbase->first = link;
}
listbase->last = link;
}
void WM_event_add_notifier(const bContext*C, unsigned int type, void*reference)
{
ARegion*ar;wmWindowManager*wm= CTX_wm_manager(C);
if (wm_test_duplicate_notifier(wm, type, reference))
{
return;
}
wmNotifier*note =(wmNotifier*)MEM_callocN(sizeof(wmNotifier), "notifier");//calloc memory
printf("0 wm= %d
",note->wm);
note->wm = wm;
//printf("1 wm= %s · %d
",note->wm->id.name,note->wm);
BLI_addtail(¬e->wm->queue, note);//crash here!!!
note->window = CTX_wm_window(C);
ar = CTX_wm_region(C);
if (ar)
note->swinid = ar->swinid;
note->category = type & NOTE_CATEGORY;
note->data = type & NOTE_DATA;
note->subtype = type & NOTE_SUBTYPE;
note->action = type & NOTE_ACTION;
note->reference = reference;
}
//----the fuction to add an notifer--------------------------
extern "C" __declspec(dllexport) void AddNotifer(bContext*C)
{
Main*bmain=CTX_data_main(C);
BKE_main_lock(bmain);
Scene*scene=C->data.scene;
WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);//ΧΧcrash
BKE_main_unlock(bmain);
}
this C++ code will compiled to dll,and call by python sctrpt in blender via ctypes.
I notice that the BLI_addtail function cause the crash,if I disable this function It will not crash ,but why?
what’s the different of immpliment this inside blender.exe from outside via calling a dll?