Issues with Instancing example

Regarding the OptiX Instancing example in the SDK, I want to do some modifications in the code for some test purposes. However, there are some issues with that.

1- Currently, the window remains open after the render. I want to close that after the display. So, I did the following change:

try {
        /* Process command line args */
        sutil::initGlut(&argc, argv);

        vector<Material> materials;
        vector<Geometry> geometries;
        Context context = createContext();
        createMaterials( context, materials );
        createGeometries( context, geometries );
        createNodeGraph( context, geometries, materials, no_accel );

        context->validate();
        context->launch( 0, width, height );
        if( outfile.empty() ) {
            sutil::displayBufferGlut( argv[0], context["output_buffer"]->getBuffer() );
	    
        } else {
            sutil::displayBufferPPM( outfile.c_str(), context["output_buffer"]->getBuffer() );
        }
        context->destroy();
	exit(0);     ///////////// I ADDED THIS
    } catch( Exception& e ) {
        sutil::reportErrorMessage( e.getErrorString().c_str() );
        exit( 1 );
    }

After making that again, I still see the window remains open.

mahmood@orca:build$ make
[ 11%] Built target sutil_sdk
[ 14%] Built target optixBuffersOfBuffers
[ 16%] Built target optixCallablePrograms
[ 19%] Built target optixConsole
[ 21%] Built target optixDenoiser
[ 23%] Built target optixDeviceQuery
[ 26%] Built target optixDynamicGeometry
[ 28%] Built target optixHello
Scanning dependencies of target optixInstancing
[ 29%] Building CXX object optixInstancing/CMakeFiles/optixInstancing.dir/optixInstancing.cpp.o
In file included from /home/mahmood/op/NVIDIA-OptiX-SDK-5.1.1-linux64/include/optixu/../internal/optix_datatypes.h:33:0,
                 from /home/mahmood/op/NVIDIA-OptiX-SDK-5.1.1-linux64/include/optixu/optixu_math_namespace.h:57,
                 from /home/mahmood/op/NVIDIA-OptiX-SDK-5.1.1-linux64/SDK/optixInstancing/optixInstancing.cpp:43:
/usr/local/cuda-10.0/include/host_defines.h:54:2: warning: #warning "host_defines.h is an internal header file and must not be used directly.  This file will be removed in a future CUDA release.  Please use cuda_runtime_api.h or cuda_runtime.h instead." [-Wcpp]
 #warning "host_defines.h is an internal header file and must not be used directly.  This file will be removed in a future CUDA release.  Please use cuda_runtime_api.h or cuda_runtime.h instead."
  ^~~~~~~
[ 30%] Linking CXX executable ../bin/optixInstancing
[ 30%] Built target optixInstancing
[ 33%] Built target optixMDLDisplacement
[ 35%] Built target optixMDLExpressions
[ 38%] Built target optixMDLSphere
[ 40%] Built target optixMeshViewer
[ 42%] Built target optixMotionBlur
[ 45%] Built target optixParticles
[ 47%] Built target optixPathTracer
[ 50%] Built target optixPrimitiveIndexOffsets
[ 52%] Built target optixProgressiveVCA
[ 57%] Built target optixRaycasting
[ 59%] Built target optixSelector
[ 61%] Built target optixSphere
[ 64%] Built target optixSpherePP
[ 66%] Built target optixTextureSampler
[ 69%] Built target optixTutorial
[ 71%] Built target optixWhitted
[ 76%] Built target primeInstancing
[ 80%] Built target primeMasking
[ 85%] Built target primeMultiBuffering
[ 90%] Built target primeMultiGpu
[ 95%] Built target primeSimple
[100%] Built target primeSimplePP
mahmood@orca:build$ 
mahmood@orca:build$ ./bin/optixInstancing 
^C

As you can see, I have to press ^C.
How can I resolve that?

The call to sutil::displayBufferGlut() starts an event loop which draws the window and waits for key/mouse events. You can prove this by sprinkling printfs around the code or breaking in a debugger.

If you want to save an image and exit, then set the output filename to something non empty and the other code path – sutil::displayBufferPPM – will be taken. Instead of opening an interactive window, it writes an image to a file and then exits.