opengl - Can't release textures created by a shared context -


i met problem using shared contexts:

i have 2 threads , each has 1 context, thr1(thread1) ctx1(context1) , thr2 , ctx2. ctx2 created sharing ctx1.

then, in thr2, create textures ctx2 current context, , rendering. after that, destroy ctx2 , finish thr2.

now problem arised: after destroy ctx2, textures created under ctx2 not released(some of then, not all). use gdebugger profile program, , see that, these textures not released, , listed under ctx1.

as repeat create thr2/ctx2 , create textures , destroy thr2/ctx2, textures getting more , more, memory.

what have tried:

delete textures in thr2 before destroy ctx2;

in thr2 make ctx1 current , try delete textures, before ctx2 destroy;

this sounds expected behavior.

to explain lifetime of objects multiple contexts, i'm going use word "pool" describe collection of textures. don't think there's universal terminology concept, anything.

while may picture textures being owned context, in fact owned pool. long have single context, that's academic difference. context owns pool, pool owns textures created in context. when context destroyed, pool goes away it, in turn destroys textures in pool.

now, 2 sharing contexts, things more interesting. still have one pool, both contexts have shared ownership for. when create texture in 1 of 2 contexts, texture owned shared pool. when context deleted, gives shared ownership of pool. pool (including textures in pool) stays around long @ least 1 of contexts alive.

in scenario, context 2 creates texture. texture added pool shared context 1 , context 2. delete context 2. created texture remains in pool. pool remains alive because context 1 (which still exists) has shared ownership of pool. means texture remains alive. irrelevant context 2 created texture, since texture owned pool, not context 2.

therefore, if want delete texture, you'll have make gldeletetexture() call. not matter if make call in context 1 or context 2.

there subtle aspects when shared textures deleted, related example textures being fbo attachments, or textures being deleted in 1 context while being bound in context. since not @ core of question, , it's complicated, i'll refer spec details (see example section d.1.2 on page 337 of opengl 3.3 spec).


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -