Error encountered: GL_INVALID_OPERATION in three.js while executing glDrawArrays: trying to access vertices outside the valid range in attribute 1

I've been struggling with this issue for quite some time now. I am in the process of creating a game, and the main map is a model in obj format. I load it using the following code snippet:

var objLoader = new THREE.OBJLoader();
objLoader.setPath('Assets/');

objLoader.load('prison.obj', function(prison){
    prison.rotation.x = Math.PI / 2;
    prison.position.z += 0.1;
    prison.scale.set(15, 15, 15)
    scene.add(prison);
});

Initially, when loading a smaller version of the same model, everything worked fine. However, as I added more details to the model, making it larger, WebGL started throwing the following warning: [.WebGL-0x7fb8de02fe00]GL ERROR :GL_INVALID_OPERATION : glDrawArrays: attempt to access out of range vertices in attribute 1. This warning appears 256 times before WebGL stops and says WebGL: too many errors, no more errors will be reported to the console for this context.

https://i.sstatic.net/hExFK.png

Due to this warning, my model fails to load completely. In the Preview, the model looks like this, as expected:

https://i.sstatic.net/YQ9Sf.png

However, in Three.js, the model appears different:

https://i.sstatic.net/qdzX0.png

At this point, I'm unsure about what might be causing the issue:

  1. It could be due to using OBJLoader CDN
  2. The size of my model might be too large
  3. Maybe I am missing something crucial

Any assistance would be greatly appreciated. Please let me know if you require more information.

Answer №1

This issue arises when the number of geometry attributes in your model do not align. For example, your geometry may have:

  • 100 vertex positions
  • 99 vertex normals
  • 99 vertex UVs

...or a similar discrepancy. The error message indicates an attempt to access vertices that are out of range.

It is recommended to re-export the OBJ asset to automatically resolve this issue. However, if obtaining a new OBJ file is not possible, you can consider the following solutions:

  • Hide the problematic geometry from rendering using mesh.visibility = false
  • Adjust the geometry attribute count by identifying and addressing the attribute shortfall:
// Assuming the problematic mesh is already identified.
const problemGeometry = mesh.geometry;

// Examine each attribute in the console to determine the shortfall.
// Check the attribute.count property to identify the deficit.
console.log(problemGeometry.attributes);

// Set the draw range to match the lowest attribute count
// For example, setting it to 99
problemGeometry.setDrawRange(0, 99);

Also, ensure to review the geometry.index attribute, if applicable, to align all attributes with the same count. Refer to this link for more details on setDrawRange

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why is the second row of inputs not displaying in Vue.js?

I am currently developing a Single Page Application (SPA) that includes options with variants, similar to the image shown below: [1]: https://i.sstatic.net/82I5U.png However, I have encountered an issue where the second row of inputs for variants is not b ...

Designing a web application with Angular2

As a newcomer to Angular2, I have recently started working on creating a simple hello world application. I have come across the concept of Modules and Components in Angular2. My main source of confusion lies in how to properly design an Angular2 applicat ...

Prevent methods from being called in a Typescript class after they have already

I encountered a scenario where I need to exclude certain methods from the return type of a class method once they have been called. Consider a class named Setup with methods step1, step2, and step3. class Setup { step1() { return this; } ...

Transform a Django/Python dictionary into a JavaScript dictionary using JSON

I need to convert a Python dictionary into a JavaScript dictionary. From what I understand, I have to first convert the Python dict into JSON format and then transform it into a JavaScript Object. view.py jsonheaderdict = json.dumps(headerdict) {{jsonhe ...

Reverting Changes Made with JQuery Append

I have a table where each cell contains a button. When the button is pressed, it adds text to the cell. I am looking for a way to remove this text from the cell when the same button is pressed again. It's important to note that this button appears mul ...

What is the reason behind having all bindings resolved during each $digest cycle?

Upon placing a breakpoint on a bound function, I discovered that it is being triggered every cycle. This came as a surprise to me as the timer displaying a countdown on the page was updating other properties as well. The demonstration below showcases thre ...

Creating a type definition for the createSelector function based on the useQuery result

Struggling to find the correct typings for the createSelector res parameter from redux-js, especially in TypeScript where there are no examples or explanations available. The only guidance is provided in JS. const selectFacts = React.useMemo(() => { ...

Encountering a "file or directory not found" error during the installation of ply using

I recently stumbled upon an interesting project for testing Rest APIs. I was in the process of installing ply from https://github.com/ply-ct/ply npm install ply-ct --save-dev Encountered this error, wondering if anyone has a solution npm WARN saveError EN ...

fullpage.js: the content exceeds the height limit

I am currently working on customizing the jquery script fullpage.js for a website built on the French CMS "SPIP" (). This script is used to create a one-page website with both horizontal and vertical navigation. However, I have encountered an issue with ...

Tips for handling a disabled button feature in Python Selenium automation

When trying to click this button: <button id="btn-login-5" type="button" class="m-1 btn btn-warning" disabled="">Update</button> I need to remove the disable attribute to make the button clickable. This ...

The NPM START ERROR message is indicating a problem with locating a file in npm

Having an issue with npm while trying to set up a basic server using node.js. Hello network! I've searched through forums, videos, and articles for solutions, but none have resolved my problem. The error message indicates that the package.json file ...

The Discord.js bot is currently experiencing an UnhandledPromiseRejectionWarning: TypeError due to the inability to access the property 'user' which is showing as undefined

I'm currently navigating the complexities of altering my Discord bot's status. I find myself in a state of confusion as I attempt to grasp the concept of promises, which seems to be playing a role in my struggle. Additionally, Discord's read ...

Utilize $validators during blur/focus interactions

In my validation directive, I currently manually set the validation state like this: $element.on('focus', function() { $scope.$apply(function() { ngModelCtrl.$setValidity('length', true); }); }); $element.on('blu ...

The declaration for "Control" is not present, possibly being restricted by its protection level

I'm really struggling to get the jQuery datepicker working in ASP.NET. I've tried various examples, but nothing seems to work for me. Even though I'm fairly new to ASP.NET, I am learning quickly! Here is the script I am trying to use: < ...

The method for transferring text box values to the next page using a hyperlink in JSP is as follows:

Is there a way to pass the values of a text box in a JSP through a hyperlink on the same page? I want to achieve this but am not sure how. ...

Simplified React conditional rendering made easy

Currently, I am utilizing React 16 with Material-Ui components. In my root component, I have a requirement to load a tab and a view conditionally based on a property. Although I have managed to implement this functionality, the code appears quite messy a ...

Endless cycle of Facebook login prompts

Currently, I am utilizing the Facebook JavaScript SDK for a login button on my website. The functionality is working correctly, but there are two specific use cases where I seem to be encountering some issues. One issue arises when the Facebook cookie is ...

Error in Bootstrap table implementation leading to truncation of tbody height due to data-detail-view property

I'm currently working on integrating Bootstrap-Table's detailView feature into my project. However, when I enable data-detail-view="true" for my table, the height of the table element shrinks to 0. Strangely, clicking on any column with ...

Getting data from a URL using Node.js and Express: A beginner's guide

Currently, I am facing an issue with extracting the token value from the URL http://localhost:3000/users/reset/e3b40d3e3550b35bc916a361d8487aefa30147c8. My get request successfully validates the token and redirects the user to a password reset screen. Howe ...

Mapbox GL JS stops displaying layers once a specific zoom level or distance threshold is reached

My map is using mapbox-gl and consists of only two layers: a marker and a circle that is centered on a specific point. The distance is dynamic, based on a predefined distance in meters. The issue I'm facing is that as I zoom in and move away from the ...