oryol icon indicating copy to clipboard operation
oryol copied to clipboard

Reminder: find fix for internal dangling resource pointers

Open floooh opened this issue 10 years ago • 1 comments

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:

  1. 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.
  2. Or: enforce that all dependent resources have the same resource id: would work but limits flexibility for resource sharing
  3. 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...

floooh avatar Jun 11 '15 06:06 floooh

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

floooh avatar Nov 08 '17 16:11 floooh