From d6428d404ef9709ed0de675bc05fbadbb167fa5a Mon Sep 17 00:00:00 2001 From: micheus Date: Fri, 1 May 2026 18:41:39 -0300 Subject: [PATCH] Fixed OBJ import crashing on IEEE754 special values (nan/inf) It was reported at SourceForge that Wings3D was crashing when vertex coordinates were exported with nan/inf/1e999 values. I took a look at and I found we already a utility wings_util:string_to_float/1 that handle it partially. So, I added the 'inf' handle option and then I changed the e3d_obj and e3d_bzw to call it instead of use the list_to_float/1 directly. In order to set a inf/-inf value on import I used as reference the lower value I found in use in wings_face (1.0e-16). ref.: https://sourceforge.net/p/wings/bugs/252/ Note: Fixed the obj and bzw importers to handle nan/inf values. Thanks Dr. Mohammadreza Ashouri --- e3d/e3d_bzw.erl | 4 ++-- e3d/e3d_obj.erl | 4 ++-- src/wings_util.erl | 11 ++++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/e3d/e3d_bzw.erl b/e3d/e3d_bzw.erl index 4c722d8e3..f6fc82462 100644 --- a/e3d/e3d_bzw.erl +++ b/e3d/e3d_bzw.erl @@ -302,7 +302,7 @@ str2float(S) -> str2float_1(S). str2float_1(S) -> try - list_to_float(S) + wings_util:string_to_float(S) catch error:badarg -> str2float_2(S, []) @@ -314,7 +314,7 @@ str2float_2([H|T], Acc) when H == $e; H == $E -> (D) when $0 =< D, D =< $9 -> ok end, Acc), NumStr = reverse(Acc, ".0e") ++ T, - list_to_float(NumStr); + wings_util:string_to_float(NumStr); str2float_2([H|T], Acc) -> str2float_2(T, [H|Acc]); str2float_2([], Acc) -> diff --git a/e3d/e3d_obj.erl b/e3d/e3d_obj.erl index 6509cba45..e9d4b5d3a 100644 --- a/e3d/e3d_obj.erl +++ b/e3d/e3d_obj.erl @@ -381,7 +381,7 @@ str2float(S) -> str2float_1(S). str2float_1(S) -> try - list_to_float(S) + wings_util:string_to_float(S) catch error:badarg -> str2float_2(S, []) @@ -393,7 +393,7 @@ str2float_2([H|T], Acc) when H == $e; H == $E -> (D) when $0 =< D, D =< $9 -> ok end, Acc), NumStr = reverse(Acc, ".0e") ++ T, - list_to_float(NumStr); + wings_util:string_to_float(NumStr); str2float_2([H|T], Acc) -> str2float_2(T, [H|Acc]); str2float_2([], Acc) -> diff --git a/src/wings_util.erl b/src/wings_util.erl index 426abe414..70f6128fb 100644 --- a/src/wings_util.erl +++ b/src/wings_util.erl @@ -231,10 +231,15 @@ nonzero(Value) -> true -> Value end. -string_to_float("NaN") -> 0.0; string_to_float(Str) -> - try list_to_float(Str) - catch _:_ -> make_float2(Str) + case string:to_lower(Str) of + "nan" -> 0.0; + "inf" -> 1.0e16; + "-inf" -> 1.0e-16; + _ -> + try list_to_float(Str) + catch _:_ -> make_float2(Str) + end end. make_float2(Str) ->