Skip to content

Commit

Permalink
dispose last vrm
Browse files Browse the repository at this point in the history
  • Loading branch information
memelotsqui committed Nov 3, 2023
1 parent 675dfbe commit 44b325f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pages/Optimizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LanguageContext } from "../context/LanguageContext"
import { SoundContext } from "../context/SoundContext"
import { AudioContext } from "../context/AudioContext"
import FileDropComponent from "../components/FileDropComponent"
import { getFileNameWithoutExtension } from "../library/utils"
import { getFileNameWithoutExtension, disposeVRM } from "../library/utils"
import { loadVRM, addVRMToScene } from "../library/load-utils"
import { downloadVRM } from "../library/download-utils"

Expand All @@ -20,6 +20,7 @@ function Optimizer({
} = React.useContext(SceneContext)

const [currentVRM, setCurrentVRM] = useState(null);
const [lastVRM, setLastVRM] = useState(null);
const [nameVRM, setNameVRM] = useState("");

const { playSound } = React.useContext(SoundContext)
Expand All @@ -35,9 +36,11 @@ function Optimizer({
downloadVRM(model, vrmData,nameVRM + "_merged",null,4096,1,true, null, true)
}

// const debugMode = () =>{
// console.log("debug")
// }
useEffect(() => {
if (lastVRM != null)
disposeVRM(lastVRM);
setLastVRM(currentVRM);
}, [currentVRM])

// Translate hook
const { t } = useContext(LanguageContext)
Expand All @@ -54,6 +57,10 @@ function Optimizer({
const vrm = await loadVRM(path);
const name = getFileNameWithoutExtension(file.name);

if (currentVRM != null){
disposeVRM(currentVRM);
}

setNameVRM(name);
setCurrentVRM(vrm);

Expand Down

0 comments on commit 44b325f

Please sign in to comment.