Giter Site home page Giter Site logo

Comments (6)

ycw avatar ycw commented on June 17, 2024

increase the budget in asconfig.json:options.memoryBase ( say, 655360 = 640kB )

"memoryBase": 65536

then rebuild (npm run asbuild)

🥂

from babylon.font.

meshantz avatar meshantz commented on June 17, 2024

Okay, that makes sense. Thanks for the quick reply!

Is there a way to calculate what values will be a problem for a given font, or is the only way to wrap every call to builder.create with error handling to catch this error?

from babylon.font.

meshantz avatar meshantz commented on June 17, 2024

Hmm. I can't seem to recover from this error at all. I've even tried reloading the entire complier mechanism (which would be pretty heavy to do every time this error occurs) to no avail.

All subsequent calls to builder.create fail with the same error.

Here is (roughly) the reloading code I attempted:

  let compiler = await Compiler.Build(`${constants.BABYLON_FONT_WASM}`)

  let fonts: { [key in FontName]: Font } = {
    calibri: await Font.Install(fontPaths.calibri, compiler, opentype),
    consola: await Font.Install(fontPaths.consola, compiler, opentype),
    'consola-bold': await Font.Install(
      fontPaths['consola-bold'],
      compiler,
      opentype,
    ),
  }

  let builder = new TextMeshBuilder(BABYLON, earcut)

      try {
        mesh = builder.create(
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          {
            font: fonts.calibri,
            text: failingText,
            size: 12,
          },
          scene,
        )
      } catch (error) {
        Compiler.Build(`${constants.BABYLON_FONT_WASM}`).then(
          async (newCompiler) => {
            compiler = newCompiler
            fonts = {
              calibri: await Font.Install(
                fontPaths.calibri,
                compiler,
                opentype,
              ),
              consola: await Font.Install(
                fontPaths.consola,
                compiler,
                opentype,
              ),
              'consola-bold': await Font.Install(
                fontPaths['consola-bold'],
                compiler,
                opentype,
              ),
            }
            builder = new TextMeshBuilder(BABYLON, earcut)
            builder.create(
              // eslint-disable-next-line @typescript-eslint/ban-ts-comment
              // @ts-ignore
              {
                font: fonts.calibri,
                text: 'small',
                size: 12,
              },
              makeOpts.scene,
            )
          },
        )
      }

from babylon.font.

ycw avatar ycw commented on June 17, 2024

a workaround off the top of my head

bytes required for (font, text) can be computed by:

function bytes_required(font, text) {
  let b = 0
  const cmds = font.raw.getPath(text, 0, 0, 100).commands
  for (const cmd of cmds) {
    b += 1
    switch (cmd.type) {
      case 'M': 
      case 'L': b += 16; break
      case 'Q': b += 48; break
      case 'C': b += 64; break 
    }
  }
  return b
}

then, validate before each builder.create:

if ( bytes_required(font, 'hello') <= 65536 ) {
  // builder.create( .. )
} 

where 65536 := asconfig.json:options.memoryBase

🥂

from babylon.font.

meshantz avatar meshantz commented on June 17, 2024

Awesome. Thanks again! I'll give this a shot.

from babylon.font.

ycw avatar ycw commented on June 17, 2024

solved in v4.

from babylon.font.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.