Handling Opengl error Out of memory

Hi, I’m trying to make an adaptive volume loader, first trying to load super big volume that will probably not fit into the memory and then decrease the volume dimensions and try again until the volume actually loads.
I’ve used ErrorObserver example to intersept error messages, then I rebuild the volume data. This generally works.
The problem I’ve seen happen is when I try to load the volume of size 23gb, while my free memory is 5gb, I catch “Out of memory”, then try to load 3gb volume, it still gives “Out of memory” even though I have 5gb free, and only on the third try with 0.5gb it loads without error.
This doesn’t happen if I load the same 3gb volume from the start, what could be the problem, opengl not releasing resources fast enough, error hanging inside the buffer for too long? how do I manually free the opengl resources?

It is generally approached from the other way around: you load a low-resolution volume quickly to minimize “time to first image” (important quality factor of imaging software). Then, preferably in the background, you can load higher-resolution image.

In general, there is no way to safely probe the amount of memory available on a system by trying to allocate memory: your software may get immediately terminated if it tries to allocate more memory than it is permitted, or you may get virtual memory allocated that causes so much swapping that renders your entire computer unusable. It is better to allow the user to specify a maximum memory usage limit (maybe initialize that limit from value that you determine from system information; such as use maximum of 50% of total RAM by default).

Hi, Mykola,

It seems I’m missing something. Are you refering to main memory or graphics card memory? These are different resources. If you’re loading volume data to RAM, then there is nothing OpenGL can do to help you. You have to check the memory management techniques in your program.

Another reason for getting OoM errors is memory fragmentation. Sometimes you have many gigabytes free in your system, but there is no slot big enough for your big block.

regards,

Paulo

Sorry for the confusion, I was talking about graphics card memory.

I think to go the other way and load low-resolution first would be a much better approach, thanks. How would I know if the volume was loaded successfully?

I’m still confused why when having 5gb free mem, and after failing to load 20gb I’m also failing to load 3gb, even though if I load 3gb straight away, it works.

I’ve managed to fix the not loading 3gb after 23gb. If I trigger the rendering in between doing the loading (e.g. Modified() or ResetCamera() and then Render()), then it works and 3gb is loaded after the failure with 23gb. I think the opengl just needs time to deallocate the memory? idk…

2 Likes