Disposing textures in a shared context

I have a PBuffer which I use as the shared contex for the subsequent PBuffer allocations:



private static Pbuffer sc_pbuffer = null;

..

if (sc_pbuffer == null)
{
      sc_pbuffer = new Pbuffer(1, 1, new PixelFormat(8, 24, 1, samples), null, null);
      sc_pbuffer.makeCurrent();
}
                  
// allocate the new pbuffer in the sc_pbuffer context
pbuffer = new Pbuffer(getPhysicalWidth(), getPhysicalHeight(), new PixelFormat(8, 24, 1, samples), null, sc_pbuffer);
pbuffer.makeCurrent();
initGL(getWidth(), getHeight(), false);

Then I create some textures into the new pbuffer context and I see that they are effectively shared between pbuffers. That’s good.

The problem arises when I dispose one of the new pbuffers: after I dispose even only one of them, I’ll never be able to dispose textures as well. I always get a NPE in glDeleteTextures(). Why ? The textures should belong to the first shared sc_pbuffer, right ?

pseudo code:

create pbuf0;
create texture0;
create texture1;
create pbuf1;
draw texture0 to pbuf0;
draw texture1 to pbuf1;
dispose pbuf1;
dispose texture0; -------- NPE!
dispose texture1; -------- NPE!
dispose pbuf0;

Elias do you read me ??

Make sure you make the remaining pbuffer current after disposing the other one.

  • elias

I’m getting an exception when I try to make it current again:

org.lwjgl.LWJGLException: Could not share contexts
at org.lwjgl.opengl.Win32ContextImplementation.nCreate(Native Method)
at org.lwjgl.opengl.Win32ContextImplementation.create(Win32ContextImplementation.java:49)
at org.lwjgl.opengl.Context.(Context.java:119)
at org.lwjgl.opengl.Pbuffer.(Pbuffer.java:191)
at it.classx.sgl.SGLBitmap.initPbuffer(SGLBitmap.java:75)
at it.classx.sgl.SGLBitmap.(SGLBitmap.java:54)
at it.classx.sgl.SGLMaster$1.execute(SGLMaster.java:123)
at it.classx.util.CommandMasterAsynch.run(CommandMasterAsynch.java:65)
at java.lang.Thread.run(Thread.java:595)

and the following PID:

An unexpected error has been detected by HotSpot Virtual Machine:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00aa0930, pid=3552, tid=404

Java VM: Java HotSpot™ Client VM (1.5.0_03-b07 mixed mode)

Problematic frame:

j it.classx.sgl.SGLImage.()V+3

--------------- T H R E A D ---------------

Current thread (0x0ae0b570): JavaThread “CommandMasterAsynch (SGLMaster)” [_thread_in_Java, id=404]

siginfo: ExceptionCode=0xc0000005, reading address 0x0000175d

Registers:
EAX=0x00000000, EBX=0x0000175d, ECX=0x00000000, EDX=0x00000004
ESP=0x0afdf8e0, EBP=0x0afdf8fc, ESI=0x07057a73, EDI=0x0afdf900
EIP=0x00aa0930, EFLAGS=0x00010246

Top of Stack: (sp=0x0afdf8e0)
0x0afdf8e0: 0afdf8e0 07057a73 0afdf900 07058430
0x0afdf8f0: 00000000 07057ab0 0afdf904 0afdf914
0x0afdf900: 00a90155 00000005 07057ab0 0ae0b570
0x0afdf910: 00a90125 0afdf990 6d7318b8 0afdf948
0x0afdf920: 0afdfa74 0000000a 07057ab0 00a98910
0x0afdf930: 0afdfa14 00000000 0ae0b570 07057ab0
0x0afdf940: 00a73718 0ae0b570 0ae0b570 0ae0b880
0x0afdf950: 07057ab0 00000000 0afdfb98 00000000

Instructions: (pc=0x00aa0930)
0x00aa0920: 44 91 1c 59 c1 e8 1c 83 e0 0f 0f 85 0a 00 00 00
0x00aa0930: 0f be 04 19 50 e9 a4 00 00 00 83 f8 03 0f 85 09

Stack: [0x0afa0000,0x0afe0000), sp=0x0afdf8e0, free space=254k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
j it.classx.sgl.SGLImage.()V+3
v ~StubRoutines::call_stub
V [jvm.dll+0x818b8]
V [jvm.dll+0xd431d]
V [jvm.dll+0x81789]
V [jvm.dll+0x74d8f]
V [jvm.dll+0x73ca1]
V [jvm.dll+0x7c374]
j it.classx.sgl.SGLMaster$5.execute()Ljava/lang/Object;+0
j it.classx.util.CommandMasterAsynch.run()V+23
j java.lang.Thread.run()V+11
v ~StubRoutines::call_stub
V [jvm.dll+0x818b8]
V [jvm.dll+0xd431d]
V [jvm.dll+0x81789]
V [jvm.dll+0x814e6]
V [jvm.dll+0x9c06b]
V [jvm.dll+0xfe7f5]
V [jvm.dll+0xfe7c3]
C [MSVCRT.dll+0x2a3b0]
C [kernel32.dll+0xb50b]

--------------- P R O C E S S ---------------

Java Threads: ( => current thread )
0x0af10560 JavaThread “Thread-5” [_thread_blocked, id=556]
0x00357d70 JavaThread “DestroyJavaVM” [_thread_blocked, id=240]
0x0aea39c0 JavaThread “AWT-EventQueue-0” [_thread_blocked, id=2984]
0x0ae88770 JavaThread “AWT-Windows” daemon [_thread_in_native, id=2872]
0x0ae88068 JavaThread “AWT-Shutdown” [_thread_blocked, id=2480]
0x0ae814e8 JavaThread “Java2D Disposer” daemon [_thread_blocked, id=1480]
0x0ae3c400 JavaThread “ObjectPool-CleanUp (SGLImagePool)” [_thread_blocked, id=1720]
=>0x0ae0b570 JavaThread “CommandMasterAsynch (SGLMaster)” [_thread_in_Java, id=404]
0x00a6fd88 JavaThread “Low Memory Detector” daemon [_thread_blocked, id=2740]
0x00a6e408 JavaThread “CompilerThread0” daemon [_thread_blocked, id=3548]
0x00a6d5b8 JavaThread “Signal Dispatcher” daemon [_thread_blocked, id=2804]
0x00a69b58 JavaThread “JDWP Command Reader” daemon [_thread_in_native, id=1504]
0x00a689f8 JavaThread “JDWP Event Helper Thread” daemon [_thread_blocked, id=2240]
0x00a67008 JavaThread “JDWP Transport Listener: dt_socket” daemon [_thread_blocked, id=3736]
0x00a58aa0 JavaThread “Finalizer” daemon [_thread_blocked, id=3092]
0x00a57610 JavaThread “Reference Handler” daemon [_thread_blocked, id=3348]

Other Threads:
0x00a54c40 VMThread [id=896]
0x00a71208 WatcherThread [id=2256]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
def new generation total 576K, used 205K [0x02a90000, 0x02b30000, 0x02f70000)
eden space 512K, 40% used [0x02a90000, 0x02ac3410, 0x02b10000)
from space 64K, 0% used [0x02b10000, 0x02b10000, 0x02b20000)
to space 64K, 0% used [0x02b20000, 0x02b20000, 0x02b30000)
tenured generation total 2092K, used 1496K [0x02f70000, 0x0317b000, 0x06a90000)
the space 2092K, 71% used [0x02f70000, 0x030e6268, 0x030e6400, 0x0317b000)
compacting perm gen total 8192K, used 5922K [0x06a90000, 0x07290000, 0x0aa90000)
the space 8192K, 72% used [0x06a90000, 0x07058810, 0x07058a00, 0x07290000)
No shared spaces configured.

VM Arguments:
jvm_args: -Djava.library.path=C:\WINDOWS\SYSTEM32;C:\WINDOWS;C:\WINDOWS\SYSTEM32\WBEM;C:\DIGISOFT\DIGIUTIL;C:\WINDOWS\SYSTEM32;C:\DIGISOFT\DIGIUTIL\TOOLS;C:\Programmi\File comuni\GTK\2.0\bin;C:\ClassX\DEV\Java\Lib\LWJGL\ -Xbootclasspath:C:\Programmi\Java\jdk1.5.0_03\jre\lib\rt.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\jsse.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\jce.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\charsets.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\comm.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\dnsns.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\j3dcore.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\j3dutils.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\jSMSEngine.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\localedata.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\QTJava.zip;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\sunjce_provider.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\sunpkcs11.jar;C:\Programmi\Java\jdk1.5.0_03\jre\lib\ext\vecmath.jar -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,suspend=y,address=localhost:1135
java_command: it.classx.sgl.SGLTestThreads

Environment Variables:
JAVA_HOME=C:\Programmi\Java\jdk1.5.0_03
CLASSPATH=“C:\Programmi\Java\jre1.5.0_03\lib\ext\QTJava.zip”
PATH=C:\WINDOWS\SYSTEM32;C:\WINDOWS;C:\WINDOWS\SYSTEM32\WBEM;C:\DIGISOFT\DIGIUTIL;C:\WINDOWS\SYSTEM32;C:\DIGISOFT\DIGIUTIL\TOOLS;“C:\Programmi\File comuni\GTK\2.0\bin”
USERNAME=Michele
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 15 Model 3 Stepping 4, GenuineIntel

--------------- S Y S T E M ---------------

OS: Windows XP Build 2600 Service Pack 2

CPU:total 2 family 15, cmov, cx8, fxsr, mmx, sse, sse2, ht

Memory: 4k page, physical 1048044k(451496k free), swap 2521384k(1994788k free)

vm_info: Java HotSpot™ Client VM (1.5.0_03-b07) for windows-x86, built on Apr 13 2005 02:07:01 by “java_re” with MS VC++ 6.0

Addendum:

making current the previous pbuffer everything works well and the textures are disposed correctly.

I was making current the shared sc_pbuffer as it was so logical to do this (the textures should be in the shared context, so I dispose them in the shared context).

The problem is: how can I make current the “previous” pbuffer. I cannot know which pbuffer is, programmatically.