Reloading primitives throws WebGL: INVALID_OPERATION: drawElements: no ELEMENT_ARRAY_BUFFER

Working on a project for my workplace which uses cesium to visualize data.
I'm having a problem when trying to reload previously loaded primitives.
The platform runs on AngularJS framework, in the first time the map is beeing loaded everything flows and works great.
When I'm switching controllers (switching views), and the map is beeing re-constructed, the viewer.scene.primitives.add throws the mentioned error : WebGL: INVALID_OPERATION: drawElements: no ELEMENT_ARRAY_BUFFER
And all the primitives are not beeing loaded.
The primitives are all saved in an AngularJS Service (Factory actually), which means that they are not beeing re-constructed when switching between controllers(views) - they are beeing constructed once in the entire run.
So I guess there is a problem with re-loading existing primitives which were previously loaded on the viewer.
It seems that memory is beeing shared, and possibly not beeing free'd when the globe is destructed.
The wierd part - it doesnt happen with entities (viewer.entities.add).
Any suggestions ?


It’s really hard to say without seeing the example, but are you removing the primitives from the collection? I think they are destroyed by default when they are removed, so that could be causing your problem.

You can try setting the PrimitiveCollection.destroyPrimitives property to false to see if that fixes the problem.



Hi, thanks for the reply.
I'm not removing the primitives from the collection (atleast not hard-coded).
I'm first creating the primitives in the start-up of the AngularJS Service which is loaded before any other cesium component and saving them in a dictionary.
The creation is made using the following :

                var billboard = billboardCollection.add({
                    position: new Cesium.Cartesian3.fromDegrees(lat, lng),
                    image: style.SymbolName,
                    scale: style.SymbolScale,
                    show: show

After that I'm creating the map viewer in an initialization phase at the start-up of the angularJs controller, which is beeing re-constructed every time the page is loaded. (As opposite to the AngularJS service, which is re-constructed once)
I'm adding them using the following :

I'm not deleting nor removing them at all.

The problem occurs when I'm moving from the Cesium Map View to a second View (an Angular term for an HTML page that shares the Service, but has its own controller which means that when Im leaving the View, the Controller with the Cesium map viewer is beeing destroyed probably, but the Service with the Cesium primitives is still alive).

When trying to add the primitives again to the newly constructed cesium map viewer im getting the following errors :

Cesium.js:126939 WebGL: INVALID_OPERATION: drawElementsInstancedANGLE: no ELEMENT_ARRAY_BUFFER bound
Cesium.js:127546 WebGL: INVALID_OPERATION: drawElements: no ELEMENT_ARRAY_BUFFER bound

And non of the primitives are shown on the map.

I hope that this information will help you as I cant post the code \ screenshots..

Thanks in advance again

I forgot that I've made some changes in the Cesium.js file (mainly wms stuff) so the line numbers are probably not the same, the errors are in :

glDrawElementsInstanced = function(mode, count, type, offset, instanceCount) { instancedArrays.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount); };


context._gl.drawElements(primitiveType, count, indexBuffer.indexDatatype, offset);

This currently isn’t supported. Each scene has a WebGL context. When you add a primitive to a scene, it will create WebGL resources for that context the first time it is rendered. When you add that same primitive to another scene, it tries to use the WebGL resources created for the other context and generates an error because they don’t exist. It is impossible for us to tell which context a resource was created for because there is no support in the WebGL API. The only option would be to use shared resources, but that is still just a proposed extension.