Simple Addon 50 lines - Crash blender - what I do bad? I start to learn Python and Blender. But can't figure out what I do bad here.
The code is :

bl_info = {
    &quot;name&quot; : &quot;HELLO WORLD&quot;,
    &quot;author&quot; : &quot;Author&quot;,
    &quot;blender&quot; : (2, 80, 0), &quot;version&quot; : (0, 0, 1),
}

import bpy

class LODP_CM_OT_set_cam ( bpy.types.Operator ) : 
    bl_idname       = &quot;lodp_cm.set_cam&quot;
    bl_label        = &quot;Set camera brush&quot;

    def execute( self : bpy.types.Operator , context : bpy.types.Context ) : 
        obj  = bpy.context.active_object

        bpy.context.view_layer.objects.active = None
        bpy.context.view_layer.objects.active = obj

        mod : bpy.types.DynamicPaintModifier = obj.modifiers.new( &quot;Dynamic Paint&quot;, &quot;DYNAMIC_PAINT&quot; )
        mod.ui_type = &quot;BRUSH&quot;
        
        # CRITICAL ERROR -  EXCEPTION_ACCESS_VIOLATION - 0x00007FF73793DDB0
        bpy.ops.dpaint.type_toggle( type=&quot;BRUSH&quot; ) 
        # CRITICAL ERROR -  EXCEPTION_ACCESS_VIOLATION - 0x00007FF73793DDB0

        return {&quot;FINISHED&quot;}
# end class LODP_CM_OT_set_cam

class LODP_CM_PT_main ( bpy.types.Panel ) : 
    bl_label        = &quot;HELLO WORLD PANEL&quot;
    bl_idname       = &quot;LODP_PT_main&quot;
    bl_space_type   = 'PROPERTIES'
    bl_region_type  = 'WINDOW'
    bl_context      = &quot;scene&quot;

    def draw(self, context):
        layout = self.layout
        layout.operator( LODP_CM_OT_set_cam.bl_idname )
#

classes = [ LODP_CM_OT_set_cam, LODP_CM_PT_main, ]

def register():
    global classes
    for klass in classes : bpy.utils.register_class( klass )
#
def unregister():
    global classes
    for klass in classes : bpy.utils.unregister_class( klass )
    classes.clear()
#
if not __package__ : register()


representative gif :

After trying to get the code of the error or something,
get : EXCEPTION_ACCESS_VIOLATION - 0x00007FF73793DDB0, exit code 11
Is a mistake, bug, bad syntaxis, another thing? , but since I'm a newcomer, I have my doubts.
Is it as simple as it could be?.
A TL;DR comment turned into answer:
Doesn't crash for me... but does throw errors. Some of the issues as I see them.
Sure it's a simple little addon, but.. appears to be some added and IMO unnecessary complexity added too. (bling).
Is there really any need to type hint the usual suspects  and  familiar arguments of  self, context ?
def execute( self : bpy.types.Operator , context : bpy.types.Context )

Let's look at  Text Editor &gt; Templates &gt; Python &gt; Operator Simple and make a small change
def execute(self, context):
    print(type(self))
    main(context)
    return {'FINISHED'}

output
&lt;class '__main__.SimpleOperator'&gt;
&lt;bpy_struct, Object(&quot;Armature&quot;) at 0x7f1e0c715008&gt;

ie the operator type is not an instance of  bpy.types.Operator
Any need to toggle the active object?
There is no need to toggle the active object with
context.view_layer.objects.active = None
context.view_layer.objects.active = obj

and  since context is an argument of method there is never any need to see bpy.context
Dynamic Paint Modifier.
Once a dynamic paint modifier is added to an object, it cannot be added again.  If you try and do so again it will not add a modifier and return None. (NoneType) is not an instance of bpy.types.DynamicPaintModifier
Main thread.
Any benefit in using if not __package__ vs if __name__ == &quot;__main__&quot; ?  Will it always equate?