Skip to content

Commit

Permalink
Fix: leak when using createForParentMesh #290
Browse files Browse the repository at this point in the history
  • Loading branch information
brianzinn committed May 18, 2023
1 parent 4dcb84c commit 2208e8d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 18 deletions.
2 changes: 1 addition & 1 deletion devtool/gatsby-mdx-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"unist-util-visit": "^2.0"
},
"peerDependencies": {
"gatsby": "^4.0"
"gatsby": "4.x"
},
"devDependencies": {
"@types/node": "^17.0.8",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"typescript": ">=4.6.2"
},
"engines": {
"node": ">=16.0.0 <17.0.0",
"node": ">=16.0.0",
"npm": ">=8.0.0"
},
"lint-staged": {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-babylonjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"test:coverage": "c8 --reporter=lcov --reporter=text-summary npm run test"
},
"devDependencies": {
"@babylonjs/core": "^6.0.0",
"@babylonjs/gui": "^6.0.0",
"@babylonjs/core": "^6.3.1",
"@babylonjs/gui": "^6.3.1",
"@rollup/plugin-json": "^4.0.2",
"@rollup/plugin-replace": "^3.0.0",
"@types/lodash.camelcase": "^4.3.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial.js'
import { Color3 } from '@babylonjs/core/Maths/math.color.js'
import { Mesh } from '@babylonjs/core/Meshes/mesh.js'
import { AdvancedDynamicTexture } from '@babylonjs/gui/2D/advancedDynamicTexture.js'
import { Grid } from '@babylonjs/gui/2D/controls/grid'
import { Grid } from '@babylonjs/gui/2D/controls/grid.js'
import { Nullable } from '@babylonjs/core/types.js'
import { CreatedInstance } from '../CreatedInstance'
import { ADTCustomProps, VirtualKeyboardCustomProps } from '../CustomProps'
import { FiberAdvancedDynamicTextureProps } from '../generatedProps'
Expand All @@ -12,6 +13,14 @@ export default class AdvancedDynamicTextureLifecycleListener extends BaseLifecyc
AdvancedDynamicTexture,
FiberAdvancedDynamicTextureProps
> {
private materialRef: Nullable<StandardMaterial> = null

onUnmount(): void {
if (this.materialRef !== null) {
this.materialRef.dispose()
}
}

onMount(instance: CreatedInstance<AdvancedDynamicTexture>): void {
instance.state = { added: true } // allow children to attach
this.addControls(instance)
Expand All @@ -22,7 +31,10 @@ export default class AdvancedDynamicTextureLifecycleListener extends BaseLifecyc
const mesh: Mesh = instance.parent!.hostInstance // should crawl parent hierarchy for a mesh
// console.error('we will be attaching the mesh:', mesh.name, mesh);

const material = new StandardMaterial('AdvancedDynamicTextureMaterial', mesh.getScene())
const material = (this.materialRef = new StandardMaterial(
'AdvancedDynamicTextureMaterial',
mesh.getScene()
))
material.backFaceCulling = false
material.diffuseColor = Color3.Black()
material.specularColor = Color3.Black()
Expand Down
20 changes: 20 additions & 0 deletions packages/static/content/examples/gui/2d-gui/2DGUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh'
import { Camera, Texture } from '@babylonjs/core'
import { Control } from '@babylonjs/gui/2D/controls/control'

// https://github.com/sebavan/BabylonjsInkSample/blob/master/src/debug/appDebug.ts
// To get inspector to load
// import "@babylonjs/core/Legacy/legacy";
// import "@babylonjs/core/Debug/debugLayer";
// import "@babylonjs/inspector";

const DEFAULT_BOXES = [
{
name: 'red',
Expand All @@ -30,6 +36,19 @@ const DEFAULT_BOXES = [
},
]

// const Inspector = () => {
// const scene = useScene();
// useEffect(() => {
// if (scene) {
// scene.debugLayer.show();
// } else {
// console.log('no scene')
// }
// }, [])

// return null;
// };

const UIComponent: FC = () => {
const plane = useRef<Mesh | undefined>(undefined)
const [showModal, setShowModal] = useState(false)
Expand Down Expand Up @@ -302,6 +321,7 @@ const UIComponent: FC = () => {
webVROptions={{ createDeviceOrientationCamera: false }}
enableInteractions
/>
{/* <Inspector /> */}
</Scene>
</Engine>
)
Expand Down
6 changes: 1 addition & 5 deletions packages/static/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,8 @@ if (config.pwa && config.pwa.enabled && config.pwa.manifest) {
plugins.push('gatsby-plugin-remove-serviceworker')
}

// check and remove trailing slash
if (config.gatsby && !config.gatsby.trailingSlash) {
plugins.push('gatsby-plugin-remove-trailing-slashes')
}

module.exports = {
trailingSlash: 'always',
pathPrefix: config.gatsby.pathPrefix,
siteMetadata: {
title: config.siteMetadata.title,
Expand Down
13 changes: 12 additions & 1 deletion packages/static/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ exports.createPages = ({ graphql, actions }) => {
})
}

exports.onCreateWebpackConfig = ({ actions }) => {
/**
* @babylonjs/inspector -> Reference error: document is not defined for "babylon.inspector.bundle.max.js"
*/
exports.onCreateWebpackConfig = ({ actions, loaders }) => {
actions.setWebpackConfig({
module: {
rules: [
{
test: /babylon\.inspector/,
use: loaders.null(),
},
],
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
alias: {
Expand Down
14 changes: 8 additions & 6 deletions packages/static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
"version": "0.0.1",
"dependencies": {
"@babel/plugin-proposal-export-default-from": "^7.12.13",
"@babylonjs/core": "^5.41.0",
"@babylonjs/gui": "^5.41.0",
"@babylonjs/loaders": "^5.41.0",
"@babylonjs/materials": "^5.41.0",
"@babylonjs/procedural-textures": "^5.42.0",
"@babylonjs/core": "^6.3.1",
"@babylonjs/gui": "^6.3.1",
"@babylonjs/gui-editor": "^6.3.1",
"@babylonjs/inspector": "^6.3.1",
"@babylonjs/loaders": "^6.3.1",
"@babylonjs/materials": "^6.3.1",
"@babylonjs/procedural-textures": "^6.3.1",
"@babylonjs/serializers": "^6.3.1",
"@devtool/gatsby-mdx-plugin": "*",
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
Expand Down Expand Up @@ -96,7 +99,6 @@
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.23.2",
"gatsby-plugin-remove-trailing-slashes": "^3.4.0",
"prettier": "^2.6.1",
"prettier-plugin-organize-imports": "^2.3.4",
"prism-react-renderer": "^1.2.0",
Expand Down

0 comments on commit 2208e8d

Please sign in to comment.