Tween JS leads to WebGL Context loss

Utilizing Tween.js to animate a lissajous curve in a Three.js render loop has been mostly successful. However, I have encountered an issue after around 70 iterations where WebGL crashes and displays the error message:

CONTEXT_LOST_WEBGL: loseContext: context lost
. This instability is troubling as it sometimes requires restarting the browser to restore WebGL functionality not only on this page but on others utilizing WebGL as well.

The lissajous curve is relatively low in vertices and does not involve any textures (which are known causes of WebGL context losses), leading me to believe that the problem lies in my implementation of Tween.js handling figure interpolation, specifically the .onComplete callback.

Could anyone provide insights into why this issue might be happening? Alternatively, I may need to refer to the WebGL documentation on how to deal with context loss using HandleContextLoss.

function tweenLandingLissaj(newLissaj) {

  var update = function() {
    lissajousCurve.fa = current.freqA;
    lissajousCurve.fb = current.freqB;
    lissajousCurve.fc = current.freqC;
    lissajousCurve.phaseX = current.phaseX;
    lissajousCurve.phaseY = current.phaseY;
    lissajousCurve.phaseZ = current.phaseZ;
    lissajousCurve.update();
  };

  var current = {
    freqA: lissajousCurve.fa,
    freqB: lissajousCurve.fb,
    freqC: lissajousCurve.fc,
    phaseX: lissajousCurve.phaseX,
    phaseY: lissajousCurve.phaseY,
    phaseZ: lissajousCurve.phaseZ
  };

  var tweenTo = new TWEEN.Tween(current);
  tweenTo.to({
    freqA: newLissaj.freqA,
    freqB: newLissaj.freqB,
    freqC: newLissaj.phaseC,
    phaseX: newLissaj.phaseX,
    phaseY: newLissaj.phaseY,
    phaseZ: newLissaj.phaseZ
  }, 6000);
  tweenTo.onUpdate(update);
  tweenTo.onComplete(function() {
  
    tweenTo.to({
      freqA: Math.floor(Math.random() * 10) + 1,
      freqB: Math.floor(Math.random() * 10) + 1,
      freqC: Math.floor(Math.random() * 10) + 1,
      phaseX: Math.floor(Math.random() * 10) + 1,
      phaseY: Math.floor(Math.random() * 10) + 1,
      phaseZ: Math.floor(Math.random() * 10) + 1
    }, 6000);
    tweenTo.start();

  });

  tweenTo.start();

}

Answer №1

After extensive investigation, the root cause of the WebGL context loss linked to Tween.js still eludes me. It appears that the issue may have been connected to my utilization of the onComplete callback in some way.

Nevertheless, I have devised a more refined approach using the Tween.js library to achieve the desired effect without encountering any loss of context.

Through the clever chain of two randomly generated tweens, I can effortlessly create an endlessly evolving lissajous curve without relying on the problematic onComplete callback that previously plagued my work.

For those encountering similar challenges, feel free to refer to the solution outlined below:

function tweenLandingLissaj(newLissaj) {

  var update = function() {
    lissajousCurve.fa = current.freqA;
    lissajousCurve.fb = current.freqB;
    lissajousCurve.fc = current.freqC;
    lissajousCurve.phaseX = current.phaseX;
    lissajousCurve.phaseY = current.phaseY;
    lissajousCurve.phaseZ = current.phaseZ;
    lissajousCurve.update();
  };

  var current = {
    freqA: lissajousCurve.fa,
    freqB: lissajousCurve.fb,
    freqC: lissajousCurve.fc,
    phaseX: lissajousCurve.phaseX,
    phaseY: lissajousCurve.phaseY,
    phaseZ: lissajousCurve.phaseZ
  };

  var tweenTo = new TWEEN.Tween(current);
  tweenTo.to({
    freqA: Math.floor(Math.random() * 10) + 1,
    freqB: Math.floor(Math.random() * 10) + 1,
    freqC: Math.floor(Math.random() * 10) + 1,
    phaseX: Math.floor(Math.random() * 10) + 1,
    phaseY: Math.floor(Math.random() * 10) + 1,
    phaseZ: Math.floor(Math.random() * 10) + 1
  }, 10000);
  tweenTo.onUpdate(update);

  var tweenBack = new TWEEN.Tween(current);
  tweenBack.to({
    freqA: Math.floor(Math.random() * 10) + 1,
    freqB: Math.floor(Math.random() * 10) + 1,
    freqC: Math.floor(Math.random() * 10) + 1,
    phaseX: Math.floor(Math.random() * 10) + 1,
    phaseY: Math.floor(Math.random() * 10) + 1,
    phaseZ: Math.floor(Math.random() * 10) + 1
  }, 10000);
  tweenBack.onUpdate(update);

  tweenTo.chain(tweenBack);
  tweenBack.chain(tweenTo);

  tweenTo.start();

}

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

Importing objects using Three.js OBJLoader without automatically adding them to the scene

I have been working on a function in Three.js to load obj files. Instead of directly adding the object to the scene within that function, I am trying to return it to the calling function. Here is the current code: var loadObjFile = function(modelConfigu ...

Top method for saving information on page for Ajax calls

On my dynamically generated page, there is an array of data produced by php that I want to utilize for an ajax request. However, I am unsure of the best method to store this data on the page as it is not sensitive and does not involve a form. Currently, I ...

What is the process for performing an Inner Join using SEQUELIZE?

My data is stored in two tables: Table 1: ID Name Email First row row Second row row Table 2: ID Number Status First row row Second row row I have defined JS models for each table. This is the model for Table 1: import Sequelize f ...

Transforming a php object into a javascript array

I have a function called selectAll that returns results as objects. $customers = $app['database']->selectAll('customers'); Below is the var_dump of the $customers variable: array(4) { [0]=> object(stdClass)#5 (7) { ["id"]= ...

it results in an error when attempting to deconstruct an object

Using a style object in a component <Temp styles={{fontWeight: 'bold', fontSize: '1.6'}} ...otherprops /> Encountering an error while deconstructing the style object Cannot read property 'fontSize' of undefined. The d ...

Interactive carousel featuring thumbnail navigation and central highlighting of images

I've been struggling with this issue for the majority of the day, so any assistance would be greatly appreciated. My goal is to find a carousel that includes both next and previous navigation buttons attached to the main image. Additionally, I am loo ...

ways to incorporate searching within JSON data using AJAX and jQuery in JavaScript

My search box needs to have JSON data appended into it. Below is the HTML code: <input type="search" id="merchantName" name="merchant" placeholder="enter merchant name"></input> I have JSON data containing merchant names that I want to appen ...

Managing various swipe interactions using HTML and JavaScript/jQuery

I'm in the process of creating a mobile multiplayer game using HTML5 and Javascript. The jQuery Plugin "touchwipe" is utilized to manage swipe events in various divs like this: $('#play1').touchwipe({ wipeLeft: function(){ if ...

The route handler is not being invoked

Currently implementing a basic login/logout system using passport.js. Strangely, the router.get('/signout', function(req, res)) is not triggering when attempting to run http://localhost:3000/auth/signout on Advanced Rest Client. Instead, an Inter ...

Beginning Vue data using asynchronous JavaScript requests

I am attempting to populate a Vue instance with data retrieved from a JsonResult through an AJAX request. Interestingly, my Vue successfully receives the data when I encode it from my View Model, but encounters issues when I try to fetch it using AJAX. Bel ...

How the Marvel of jQuery Ignites the Power of

I require some assistance with the callbacks. It appears that they are not functioning properly. I am in the process of creating a jQuery-based game. I have designated a <div id='button'></div> for all the buttons that will be used ...

React.js TypeScript Error: Property 'toLowerCase' cannot be used on type 'never'

In my ReactJS project with TSX, I encountered an issue while trying to filter data using multiple key values. The main component Cards.tsx is the parent, and the child component is ShipmentCard.tsx. The error message I'm receiving is 'Property &a ...

It appears that Vue.js's this.$nextTick() function does not properly wait for the DOM to finish rendering

Having trouble with nextTick() in Vue. Here's the template code: In the template: <template> <div> <div v-if="editing"> <span ref="theInput" contenteditable="true">{{ someValue }}</span> < ...

Retrieve telephone number prefix from Cookies using React

Being able to retrieve the ISO code of a country is possible using this method: import Cookies from 'js-cookie'; const iso = Cookies.get('CK_ISO_CODE'); console.log(iso); // -> 'us' I am curious if there is a method to obt ...

Encountering an issue with locating an argument in a JSON file

My JSON file seems to have an error, and I'm not sure where the issue lies within my data blocks. I attempted using jsonpathfinder for reading but encountered a syntax error. { "data": [ { "gender": "male" } ] }{ "data": [ { ...

Implementing volume controls for several Audiojs audio players using JS

I'm currently working on implementing a volume slider for the audiojs player. While I've managed to set up the slider and link it to the player successfully, I'm facing an issue where it only functions with the initial instance of the player ...

Result box not displaying the expected JQuery UI Autocomplete results

Can someone assist me with Autocomplete? When I search for an RTO code, the result box appears but without a list (refer to Screen : 1). However, when I press the down arrow button on the keyboard, the list starts appearing one by one (as shown in Screen : ...

How to Redirect between Controllers in Nest.Js

I'm currently working with a module that looks like this: @Module({ imports: [], controllers: [AppController, AnotherController], providers: [], }) Within the AppController, I am attempting to implement res.redirect('/books') which r ...

Ways to showcase information in real-time based on user interaction

I've created a form (php file) that enables users to input investment information into the database. They can choose investments from a dropdown list (previously entered into the database), add additional details, and submit them to the database. I&ap ...

The width and sharpness of lines in Google Charts may vary

Upon closer inspection, I have noticed variations in line thickness and sharpness despite setting their properties to be the same. Despite searching extensively on the Google Charts webpage, I have been unable to find a solution for this issue. Can anyone ...