Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash while processing a particular lens prescription #23

Open
10110111 opened this issue Jul 12, 2020 · 4 comments
Open

Crash while processing a particular lens prescription #23

10110111 opened this issue Jul 12, 2020 · 4 comments

Comments

@10110111
Copy link

I was trying to process (by example from data subdirectory) the prescription for Canon EF-S10-18mm f4.5-5.6 IS STM. But gopt aborts with the following output (and backtrace via GDB).

$ gdb -q -ex r --args ./cmd/gopt /tmp/JP2015-031869_Example01P.txt 
Reading symbols from ./cmd/gopt...
Starting program: /home/ruslan/src/goptical-fork/build/cmd/gopt /tmp/JP2015-031869_Example01P.txt
material created air
material created air
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
material created dielectric
system:
   [1]N8goptical3sys4LensE at [0, 0, 0]
   [28]N8goptical3sys5ImageE at [0, 0, 117.61]
   [29]N8goptical3sys11SourcePointE at [0, 0, -1e+09]
sequence:
   [29]N8goptical3sys11SourcePointE at [0, 0, -1e+09]
   [2]N8goptical3sys14OpticalSurfaceE at [0, 0, 0] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [3]N8goptical3sys14OpticalSurfaceE at [0, 0, 1.2] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [4]N8goptical3sys14OpticalSurfaceE at [0, 0, 1.41] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [5]N8goptical3sys14OpticalSurfaceE at [0, 0, 4.41] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [6]N8goptical3sys14OpticalSurfaceE at [0, 0, 18.38] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [7]N8goptical3sys14OpticalSurfaceE at [0, 0, 19.23] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [8]N8goptical3sys14OpticalSurfaceE at [0, 0, 25.09] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [9]N8goptical3sys14OpticalSurfaceE at [0, 0, 25.95] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [10]N8goptical3sys14OpticalSurfaceE at [0, 0, 26.1] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [11]N8goptical3sys14OpticalSurfaceE at [0, 0, 29.45] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [12]N8goptical3sys14OpticalSurfaceE at [0, 0, 47.57] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [13]N8goptical3sys14OpticalSurfaceE at [0, 0, 48.79] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [14]N8goptical3sys14OpticalSurfaceE at [0, 0, 50.08] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [15]N8goptical3sys14OpticalSurfaceE at [0, 0, 50.88] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [16]N8goptical3sys14OpticalSurfaceE at [0, 0, 53.86] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [17]N8goptical3sys4StopE at [0, 0, 56.03]
   [18]N8goptical3sys14OpticalSurfaceE at [0, 0, 60.07] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [19]N8goptical3sys14OpticalSurfaceE at [0, 0, 60.87] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [20]N8goptical3sys14OpticalSurfaceE at [0, 0, 64.2] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [21]N8goptical3sys14OpticalSurfaceE at [0, 0, 64.35] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [22]N8goptical3sys14OpticalSurfaceE at [0, 0, 68.57] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [23]N8goptical3sys14OpticalSurfaceE at [0, 0, 69.82] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [24]N8goptical3sys14OpticalSurfaceE at [0, 0, 70.52] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [25]N8goptical3sys14OpticalSurfaceE at [0, 0, 74.32] N8goptical8material3AirILNS0_10AirFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [26]N8goptical3sys14OpticalSurfaceE at [0, 0, 75.12] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE
   [27]N8goptical3sys14OpticalSurfaceE at [0, 0, 82.26] N8goptical8material4AbbeILNS0_11AbbeFormulaE0EEE N8goptical8material3AirILNS0_10AirFormulaE0EEE
   [28]N8goptical3sys5ImageE at [0, 0, 117.61]
gopt: /home/ruslan/src/goptical-fork/include/goptical/core/data/discrete_set.hpp:132: virtual double goptical::data::DiscreteSetBase::get_x_value(unsigned int) const: Assertion `n < _data.size ()' failed.

Program received signal SIGABRT, Aborted.
0xf7fd4c69 in __kernel_vsyscall ()
(gdb) bt
#0  0xf7fd4c69 in __kernel_vsyscall ()
#1  0xf7af5592 in __libc_signal_restore_set (set=0xffffc97c) at ../sysdeps/unix/sysv/linux/nptl-signals.h:80
#2  __GI_raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:48
#3  0xf7af69b7 in __GI_abort () at abort.c:79
#4  0xf7aed67b in __assert_fail_base (fmt=0xf7c466ac "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x80b02cb "n < _data.size ()", file=0x80b0280 "/home/ruslan/src/goptical-fork/include/goptical/core/data/discrete_set.hpp", line=132, 
    function=0x80b0b00 "virtual double goptical::data::DiscreteSetBase::get_x_value(unsigned int) const") at assert.c:92
#5  0xf7aed6d9 in __GI___assert_fail (assertion=0x80b02cb "n < _data.size ()", file=0x80b0280 "/home/ruslan/src/goptical-fork/include/goptical/core/data/discrete_set.hpp", line=132, function=0x80b0b00 "virtual double goptical::data::DiscreteSetBase::get_x_value(unsigned int) const") at assert.c:101
#6  0x080536e2 in goptical::data::DiscreteSetBase::get_x_value (this=0x81025fc, n=1) at /home/ruslan/src/goptical-fork/include/goptical/core/data/discrete_set.hpp:132
#7  0x08073bcb in goptical::io::RendererSvg::draw_plot_data_2d (this=0xffffcda4, data=..., style=...) at /home/ruslan/src/goptical-fork/src/core/io_renderer_svg.cpp:216
#8  0x08076fc5 in goptical::io::RendererViewport::draw_plot (this=0xffffcda4, plot=...) at /home/ruslan/src/goptical-fork/src/core/io_renderer_viewport.cpp:274
#9  0x0805f77b in goptical::data::Plot::draw (this=0x81f44bc, r=...) at /home/ruslan/src/goptical-fork/src/core/data_plot.cpp:188
#10 0x0804b981 in analysis_fan (sys=std::shared_ptr<goptical::sys::System> (use count 2, weak count 0) = {...}, source_point=std::shared_ptr<goptical::sys::SourcePoint> (use count 3, weak count 0) = {...}, base_file_names=...) at /home/ruslan/src/goptical-fork/cmd/generic_lens.cpp:375
#11 0x0804ae16 in do_system_parallel_rays (importer=0xffffd2bc, base_file_names=..., args=...) at /home/ruslan/src/goptical-fork/cmd/generic_lens.cpp:226
#12 0x0804b242 in main (argc=2, argv=0xffffd394) at /home/ruslan/src/goptical-fork/cmd/generic_lens.cpp:277

The same gopt binary works fine with the examples in the repo, and also with another prescription I tried, for Canon EF-S24mm f2.8 STM.

@10110111
Copy link
Author

Actually, the problem seems to originate even before the attempts to plot: the tracing process appears to have lost most of the internal rays, see the layout output file:

out

@10110111
Copy link
Author

Indeed, the problem is with such lenses that cut away a fair portion of the incoming rays. I was able to work around the crash with this hack (replacing one magic number with another):

diff --git a/src/core/analysis_rayfan.cpp b/src/core/analysis_rayfan.cpp
index d7c4ce8..59e4af9 100644
--- a/src/core/analysis_rayfan.cpp
+++ b/src/core/analysis_rayfan.cpp
@@ -52,7 +52,7 @@ namespace analysis
 RayFan::RayFan (const std::shared_ptr<sys::System> &system,
                 enum rayfan_plane_e plane)
     : _tracer (system.get ()), _processed_trace (false), _entrance (0),
-      _exit (0), _dist (trace::SagittalDist, 15)
+      _exit (0), _dist (trace::SagittalDist, 150)
 {
   set_plane (plane);
 }

And the layout is rendered better when I replace a magic number here:

diff --git a/cmd/generic_lens.cpp b/cmd/generic_lens.cpp
index 40e33d0..a25d3cf 100644
--- a/cmd/generic_lens.cpp
+++ b/cmd/generic_lens.cpp
@@ -310,7 +310,7 @@ layout (const std::shared_ptr<sys::System> &sys,
 #else
     // trace and draw rays from source
     tracer.get_params ().set_default_distribution (
-        trace::Distribution (trace::MeridionalDist, 10));
+        trace::Distribution (trace::MeridionalDist, 50));
     tracer.get_trace_result ().set_generated_save_state (*source_point);
     tracer.trace ();
     tracer.get_trace_result ().draw_2d (renderer);

The layout is now:
JP2015-031869_Example01P_layout

@dibyendumajumdar
Copy link
Owner

Hi - thank you. I didn't notice this issue as I didn't get an alert somehow.

@dibyendumajumdar
Copy link
Owner

BTW Sometimes Bill Claff's data file doesn't have some values - that can cause issues. I should probably improve validation when loading the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants