oryol
oryol copied to clipboard
Reminder: find fix for internal dangling resource pointers
There are currently a few cases in the Gfx module (e.g. in class drawState), where pointers to other resources (meshes and shader progs) exist so they don't need to be resolved from Id every time they are used. This will lead to dangling pointers if the referenced resources have another resource label and are destroyed before the draw state. Need a solution that doesn't introduce complicated resource tracking:
- Obvious solution would be to resolve from Id when needed. This would still be fast since the resource id holds an index into a resource pool.
- Or: enforce that all dependent resources have the same resource id: would work but limits flexibility for resource sharing
- Or: enforce resource creation/destruction as onion-layers, resources created later must be destroyed first, also takes away flexibility
Hmmm... number 1. sounds like the best solution...
I found a nice and simple solution in sokol_gfx:
- when an internal pointer to a pool object is stored somewhere, also store its Id next to it
- before the pointer is used, compare the stored Id with the current pool-slot Id, if they are different, the pointer is dangling