美文网首页
holokit-LineRendererBase LineUni

holokit-LineRendererBase LineUni

作者: 非墨即白 | 来源:发表于2019-05-18 14:46 被阅读0次

    Bug描述:

    使用holokit给出的example里的Lineunity (继承了LineRenderBase的基类)+Bezier(继承了LineBase的基类)实现曲线

    但是出现nullpointer错误

    问题1:

    lineunity里使用的defaultlinematerial 名字使用shader.find找不到该material

    按理说,可以手动规定linematerial,这样不必使用default linematerial,也避免直接修改lineunity的代码(这个毕竟是库函数)

    但由于lineunity是直接新建Object, 然后addcomponent()得到的,

    因此在生成lineunity之前,无法指定linematerial,

    生成之后则自动跑OnEnable(),

    即在linematerial linecolor未经初始化的时候,自己使用默认值初始化并且使用了,

    这种执行顺序改不了,并且感觉很吊诡

    解决方案:

    修改lineunity(这个是暂时的,最终要么换一个库类,要么自己重写一个类似的类)

    问题2

    定义了

    [Tooltip("The source Line this component will render")]

    protected LineBase source;

    之后立即定义了

    public virtual LineBase Source

            {

                get

                {

                    if (source == null)

                    {

                        source = GetComponent<LineBase>();

                    }

                    return source;

                }

                set

                {

                    source = value;

                    if (source == null)

                    {

                        enabled = false;

                    }

                }

            }

    让人怀疑这个程序员写什么==

    这样写的作用:

    直接引用source的时候,未经初始化。null。

    引用 Source的时候,source被初始化了,其实就是在使用source。相当于给source加了一个别名,但是必须在使用source之前调用一次Source。

    并且这个bug导致了,debug.log()在这里,是会出现薛定谔的猫现象。

    一旦log,调用了Source,就会影响结果,导致null pointer的Bug消失。

    相关文章

      网友评论

          本文标题:holokit-LineRendererBase LineUni

          本文链接:https://www.haomeiwen.com/subject/cxzjaqtx.html