Directional lights that cast shadows actually have a frustum. Try visualising it using show_frustum() and adjusting the near/far or film size properties on the orthographic lens of the directional light.
Also keep in mind that DirectionalLight is reference counted, so use a special pointer wrapper in this line:
PT(DirectionalLight) dlight = new DirectionalLight("dlight"); // eclairer scene
(1) The film size is the width and height of the frustum, when viewing directly through it.
As for the two parameters to set_shadow_caster, it represents the width and height of the shadow buffer. The two parameters need to be powers of two, and an acceptable texture size. 512x512 seems to be a popular size, but you’ll probably want to do tweaking until you find the setting that’s right for you.
(Note that the buffer does not need to be square. 8x1024 would be an acceptable size, for instance.)
Basically, every pixel on the shadow map will be film_size / buffer_size large.
(2) On a sidenote, I should point out that spot lights are easier to configure and it’s significantly easier to avoid shadowing artifacts with them, because of the slight angle.
(3) The Panda objects that inherit from ReferenceCount hold a reference count, which means that they are deleted when the reference count reaches zero. The PT() wrapper holds one reference to the object, which guarantees that it will not be deleted as long as the PT() exists. Otherwise the object might be garbage collected and you’ll get a segfault when trying to use it.
Note that you should not attempt to delete reference-counted objects yourself, this will result in a double free.
tl;dr: check in the API reference if the class inherits from ReferenceCount or not.