70001463 An event to be fire before a vdDocument is cleared

Article 70001463
Type Wish
Product Engine
Version 7016
Date Added 12/4/2018
Fixed 8.8001.0.4 (12/4/2018)
Submitted by Eric Guilhaurre

Summary

An event to be fire before a vdDocument is cleared

Solution

A new event OnBeforeDocumentClear of vdDocument was added in version 8001.0.4
Event is Fired before vdDocument object is cleared.
Overwrite it in order to do additional clear of other custom user resources
Examples
//Example 1 of free memory from some custom data

documnet.OnBeforeDocumentClear += Doc_OnBeforeDocumentClear;

object myCutomData = new data[100000];

private void Doc_OnBeforeDocumentClear(vdDocument sender)
{
myCutomData = null;
}


//Example 2 activate and clear Cutom OpenGL resources

documnet.OnBeforeDocumentClear += Doc_OnBeforeDocumentClear;

private void Doc_OnBeforeDocumentClear(vdDocument sender)
{
vdDocument document = sender as vdDocument;
if (document == null) return;
IopenglControl openglcontext = document.GlobalRenderProperties.OpenGLContext;
bool islock = openglcontext.IsLock();
if (openglcontext.LockOpenGLContect())//activate OpenGLContext in order to call opengl functions
{
//delete all list of opengl context
uint curlistid = OpenGLImports.glGenLists(1);
OpenGLImports.glDeleteLists(1, (int)curlistid);
uint[] texture = new uint[1];
OpenGLImports.glGenTextures(1, texture);
for (uint i = 0; i < texture[0]; i++)
{
uint[] binds = new uint[1];
binds[0] = i;
if (OpenGLImports.glIsTexture(i) != 0)
OpenGLImports.glDeleteTextures(1, binds);
}
}
if (!islock) openglcontext.UnLockOpenGLContect();//restore opengl curent context state
}

Send comments on this topic.