Results 1 to 2 of 2
  1. #1
    Member imdjs's Avatar
    Join Date
    Mar 2013

    why crash immediatly when adding an notifier to the scene via ctypes DLL

    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))
        wmNotifier*note =(wmNotifier*)MEM_callocN(sizeof(wmNotifier), "notifier");//calloc memory
        printf("0 wm=  %d \n",note->wm);
        note->wm = wm;
        //printf("1 wm=  %s  %d \n",note->wm->,note->wm);
        BLI_addtail(&note->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)
        WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);//ΧΧcrash
    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?

  2. #2
    Member kilon's Avatar
    Join Date
    Sep 2007
    Greece , Athens
    Crashes usually happen when there is an illegal access to memory which means access memory that is freed or that is not used or that the application is not allowed to access. Which in turn means a problem with a pointer or more.

    Finding crashes will definitely require debugging the dll and executable with C debugger like GDB or LLDB. You have to make sure your manage memory properly. Pointers are by far the biggest pain when coding in C. Ctypes may be a python library but are basically c coding too.

    Also why you cram your pointer definitions ? add a space to make code more readable. Also just because you call the DLL from python does not mean it is also linked to the blender executable. The DLL will exist in a separate place with no access to the Blender internals and memory. One of the pains of Blender not relying on DLLs.

    Unless you pass it Blender memory data via python but Blender rarely gives Python access to its internals when it does its either read only or very limited to avoid crashes like this happening. <--- This my blog, you will find things i make here like music, 3d and 2d graphics and python programming.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts