mkkellogg / GaussianSplats3D

Three.js-based implementation of 3D Gaussian splatting
MIT License
1.48k stars 191 forks source link

sortWork.js crashed when 'dynamicScene': true, with add-->remove-->add opterations. 'dynamicScene': false。 all be OK #346

Open nmgyaoyuan opened 1 month ago

nmgyaoyuan commented 1 month ago

when i want read splat file and want rotate the splat scene, i found the bug(maybe).

code: gsViewer = new GaussianSplats3D.Viewer({ 'selfDrivenMode': false, 'useBuiltInControls': false, 'dynamicScene': true, 'renderer':renderer, 'camera':camera, 'threeScene':scene, 'sphericalHarmonicsDegree': 2, 'rootElement': splatContainer.value }); //--------------------------------------------------------------

/ ----copyed from demo code---/ function runViewer(splatBufferData:ArrayBuffer, format:GaussianSplats3D.SceneFormat, alphaRemovalThreshold:number, sphericalHarmonicsDegree:number) { const splatBufferOptions = { 'splatAlphaRemovalThreshold': alphaRemovalThreshold }; const splatBufferPromise = fileBufferToSplatBuffer({data: splatBufferData}, format, alphaRemovalThreshold, 0, undefined, undefined, undefined, undefined, sphericalHarmonicsDegree );

splatBufferPromise.then((splatBuffer:GaussianSplats3D.splatBuffer) => {
    gsViewer.addSplatBuffers([splatBuffer], [splatBufferOptions])
    .then(() => {
        hasSplatInViewer=true;
        console.info('splat is added in viewer');
        emit('added',null);
    });
});

} //---------------------------------------------------------------------

use runViewer() to add splatFile , is OK. Then use removeSplatScene(0) remove a scene,is OK. and use runViewer() to add splat File again , crashed.

error info:

Uncaught RangeError: offset is out of bounds at Int32Array.set () at self.onmessage (8f7e31cd-0625-419e-9f13-6931e81b4dc9:95:11) self.onmessage @ 8f7e31cd-0625-419e-9f13-6931e81b4dc9:95 8f7e31cd-0625-419e-9f13-6931e81b4dc9:48 Uncaught RangeError: offset is out of bounds at Float32Array.set () at sort (8f7e31cd-0625-419e-9f13-6931e81b4dc9:48:59) at self.onmessage (8f7e31cd-0625-419e-9f13-6931e81b4dc9:123:7)

crashed code (2 places) : (1) ----> new Float32Array(wasmMemory, modelViewProjOffset, 16).set(modelViewProj); (2) ---->
if (e.data.centers) { centers = e.data.centers; sceneIndexes = e.data.sceneIndexes; if (integerBasedSort) { new Int32Array( wasmMemory, centersOffset + e.data.range.from Constants2.BytesPerInt 4, e.data.range.count * 4 ).set(new Int32Array(centers)); } else {

mkkellogg commented 1 month ago

Sorry for the late reply, are you making sure to wait for removeSplatScene() to complete before attempting to add another scene? It returns a promise like addSplatBuffers()

nmgyaoyuan commented 1 month ago

yes, waited for the removeSplatScene() returned promise before attempting to add another scene.

`if(gsViewer){

  gsViewer.removeSplatScene(0)
  .then(()=>{
      hasSplatInViewer=false;
      console.info('splat is removed');
      emit('deleted',null);
  })
  .catch((error:Error)=>{
      console.error(`splat remove error:${error}`);
  })

}`

crashed throw from sortWork.js 。

mkkellogg commented 3 weeks ago

If you post your full code, maybe I can run it locally and try to debug it.