gpt4 book ai didi

rust - 红 bean 杉应用程序-rustwasm错误未捕获的RangeError : Maximum call stack size exceeded

转载 作者:行者123 更新时间:2023-12-03 11:46:57 26 4
gpt4 key购买 nike

我试图将数独解决为Yew应用。使用yew =“0.17.4”版本。
但是低于错误

Uncaught RangeError: Maximum call stack size exceeded
at dlmalloc::dlmalloc::Dlmalloc::malloc::hb6b25cc27fa2f08c (wasm_bg.wasm:wasm-function[55]:0x5f0d)
at __rdl_alloc (wasm_bg.wasm:wasm-function[327]:0x23108)
at __rust_alloc (wasm_bg.wasm:wasm-function[362]:0x23480)
at alloc::raw_vec::RawVec<T,A>::reserve::h02d54539a997f0ac (wasm_bg.wasm:wasm-function[211]:0x207e4)
at <&mut W as core::fmt::Write>::write_str::he2cb1047a173d57a (wasm_bg.wasm:wasm-function[288]:0x22a02)
at core::fmt::Formatter::pad_integral::hfd6532b3a41ee584 (wasm_bg.wasm:wasm-function[104]:0x16c73)
at core::fmt::num::imp::fmt_u64::h5081cd6222065ff2 (wasm_bg.wasm:wasm-function[156]:0x1cecb)
at core::fmt::num::imp::<impl core::fmt::Display for u32>::fmt::hd7239ff7b4d279a9 (wasm_bg.wasm:wasm-function[388]:0x23617)
at <&T as core::fmt::Display>::fmt::h8b339f7b56577d63 (wasm_bg.wasm:wasm-function[392]:0x2364d)
at core::fmt::write::h8b996d8af01475c9 (wasm_bg.wasm:wasm-function[103]:0x16b15)
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=16e0219070bd7245a50a209de0ce2cd4

最佳答案

让我们回顾一下solve函数:

fn solve(&mut self)-> bool{
match self.getemptycell(){
Some((row,col)) => {
for value in 1..10{
if self.IsValidValue(row,col,value){
let index = (row*8 + row) + col ;
self.cellule[(row*8+row)+col].value = value;
log::info!("value = {}",value);
if self.solve(){ // <----------------------------- Recursion starts here
return true

}
self.cellule[(row*8+row)+col].value = 0;
}

}
return false
},
_ => {
// log::info!("{:?}",self.cellule);
return true
},

}

}
  • 函数检查一些值,如果值与条件匹配,则函数再次调用自身(line 90)。
  • 然后它将在相同条件下检查相同值,并再次调用自身。
  • 还有一次。
  • 还有一次。
  • ...
  • 直到堆栈溢出。

  • 您应该更小心递归调用。

    关于rust - 红 bean 杉应用程序-rustwasm错误未捕获的RangeError : Maximum call stack size exceeded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65573562/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com