diff --git a/panda/src/egg/config_egg.cxx b/panda/src/egg/config_egg.cxx index 2ae07a00a1..3440ea5708 100644 --- a/panda/src/egg/config_egg.cxx +++ b/panda/src/egg/config_egg.cxx @@ -151,6 +151,14 @@ ConfigVariableInt egg_test_vref_integrity "its vertices will no longer be checked for internal integrity. " "This is meaningful in non-production builds only.")); +ConfigVariableInt egg_recursion_limit +("egg-recursion-limit", 5000, + PRC_DESC("The maximum number of levels that recursive algorithms within " + "the egg library are allowed to traverse. This is a simple hack " + "to prevent deeply-recursive algorithms from triggering a stack " + "overflow. Set it larger to run more efficiently if your stack " + "allows it; set it lower if you experience stack overflows.")); + //////////////////////////////////////////////////////////////////// // Function: init_libegg // Description: Initializes the library. This must be called at diff --git a/panda/src/egg/config_egg.h b/panda/src/egg/config_egg.h index 339079fa76..45a4afa9f4 100644 --- a/panda/src/egg/config_egg.h +++ b/panda/src/egg/config_egg.h @@ -40,6 +40,7 @@ extern EXPCL_PANDAEGG ConfigVariableDouble egg_max_tfan_angle; extern EXPCL_PANDAEGG ConfigVariableInt egg_min_tfan_tris; extern EXPCL_PANDAEGG ConfigVariableDouble egg_coplanar_threshold; extern EXPCL_PANDAEGG ConfigVariableInt egg_test_vref_integrity; +extern EXPCL_PANDAEGG ConfigVariableInt egg_recursion_limit; extern EXPCL_PANDAEGG void init_libegg(); diff --git a/panda/src/egg/eggPrimitive.cxx b/panda/src/egg/eggPrimitive.cxx index c2ce28e378..615fc368b5 100644 --- a/panda/src/egg/eggPrimitive.cxx +++ b/panda/src/egg/eggPrimitive.cxx @@ -1223,7 +1223,7 @@ void EggPrimitive:: r_set_connected_shading(int stack_depth, EggPrimitive::Shading shading, const EggAttributes *neighbor, ConnectedShadingNodes &next_nodes) { - if (stack_depth > 10000) { + if (stack_depth > egg_recursion_limit) { // Too deep. Limit recursion. ConnectedShadingNode next; next._shading = shading;