ThatOpen / engine_web-ifc

Reading and writing IFC files with Javascript, at native speeds.
https://thatopen.github.io/engine_web-ifc/demo
Mozilla Public License 2.0
617 stars 190 forks source link

[Bug]: offset is out of bounds #435

Closed Garripe closed 1 year ago

Garripe commented 1 year ago

What happened?

Hi all, I am trying to save a model in a file. With small files it seems to work fine, specifically with the simple simple rebar.ifc file it does it correctly. I have not been able to do it with other files like TESTED_Simple_project_01.ifc. The function that is giving me an error is SaveModel(). This is the execution sequence:

Captura de pantalla 2023-07-10 a las 10 02 13

Captura de pantalla 2023-07-10 a las 10 02 58

As you can see in the images the dataBuffer is smaller than the src. Why is this happening? Am I doing something wrong? Thanks in advance

Version

0.0.39

What browsers are you seeing the problem on?

Chrome, Safari

Relevant log output

RangeError: offset is out of bounds
    at Uint8Array.set (<anonymous>)
    at web-ifc-api.js:62044:18
    at __emval_call (web-ifc-api.js:9241:27)
    at web-ifc.wasm:0x8f2fb
    at web-ifc.wasm:0x81686
    at web-ifc.wasm:0x9135c
    at Object.SaveModel (eval at new_ (web-ifc-api.js:8629:31), <anonymous>:9:1)
    at IfcAPI2.SaveModel (web-ifc-api.js:62041:21)
    at createDownloadLink (IFCViewer.jsx:109:27)

Anything else?

No response

beachtom commented 1 year ago

This is odd - can you share the code? Or are you literally loading and saving again a model with no changes?

Garripe commented 1 year ago

Hi @beachtom ,

I was testing with the version 0.0.35 and function ExportFilaAsIFC() and works well with any ifc file. I am using the code of the example https://ifcjs.github.io/info/docs/Guide/web-ifc/Tutorials/Editing%20Properties.

function handleChangeForIFCApi () {
    const inputButton = fileInputRef.current
    inputButton.addEventListener('change', (changed) => {
      const reader = new FileReader()
      reader.onload = () => encodeFile(reader.result)
      reader.readAsText(changed.target.files[0])
    })
  }

  async function encodeFile (ifcAsText) {
    const uint8array = new TextEncoder().encode(ifcAsText)
    await OpenIfcApi(uint8array)
    // const line = ifcAPI.GetLine(0, 186)
    // console.log(line)
    // line.Name.value = 'test'
    // ifcAPI.WriteLine(0, line)
    createDownloadLink()
  }
  async function OpenIfcApi (ifcAsText) {
    await ifcAPI.Init()
    return ifcAPI.OpenModel(ifcAsText)
  }
function createDownloadLink () {
    try {
      const data = ifcAPI.ExportFileAsIFC(0)
      const blob = new Blob([data])
      const file = new File([blob], 'modified.ifc')
      const url = URL.createObjectURL(file)
      const link = document.createElement('a')
      link.innerText = 'Download'
      link.download = 'modified.ifc'
      link.setAttribute('href', url)

      document.body.appendChild(link)
      link.click()
    } catch (error) {
      console.error(error)
    }
  }

The only thing I change with version 0.0.39 is the function ExportFileAsIFC(0) by SaveModel(0)

LukasKStavario commented 1 year ago

Hi @beachtom I have the same problem. I have updated to 0.0.42 because of deleting lines in API (I really need this feature). And it is in this version (thank you very much) but I am not able to save modified model. SaveModel and ExportFileAsIFC end with the same error that mentioned here. And for me if I am saving model that has 310 kilos error appears, if model has megabytes about tens everything works fine. So I am upvoting to repair it - thank you.

image

And no changes in model

image image

beachtom commented 1 year ago

This should be fixed now!

LukasKStavario commented 1 year ago

Thanks Tom! You mentioned in the past that it is possible to download a zip somewhere in the repository with the current build before you release it, with me replacing the specific files, where can I find it?

beachtom commented 1 year ago

There is a link on the readme under current build.

But it takesa bout 15-20 min to build the entire set - so wait a bit or the changes may not be in