Home Forums GAMES在线课程(现代计算机图形学入门)讨论区 作业5:x,y的理解和报错outside the range of type ‘char’5

Tagged: 

Viewing 4 reply threads
  • Author
    Posts
    • #11150 Score: 0
      Noah Osiris
      Participant

      关于x,y的计算,我理解的是先把在scene中的x,y坐标映射到[-1,1]上,然后在通过乘上scale和imageAspectRatio变换到世界坐标下,不知道这样理解是否有错。然后对于项目的编译没有报错,但是在运行的时候会报runtime error,具体的报错信息在图中,有大佬知道为什么吗。具体的报错代码是
      color[0] = (char)(255 * clamp(0, 1, framebuffer[i].x));
      color[1] = (char)(255 * clamp(0, 1, framebuffer[i].y));
      color[2] = (char)(255 * clamp(0, 1, framebuffer[i].z));
      我将char换成unsigned char就不会报错,但是渲染出来是黑色的,也就是说clamp返回的值始终是0,然后乘上255仍然是0,我是这么理解的不知道有没有错误。

    • #11151 Score: 0
      Noah Osiris
      Participant

      忘记上传图片了

      Attachments:
      You must be logged in to view attached files.
    • #12139 Score: 0
      unkvcc
      Participant
      2 pts

      我也是报这个错误,请问楼主弄明白了吗

    • #12145 Score: 1
      aparaburu
      Participant
      1 pt

      这个只是颜色值显式转换为char类型的过程中越界被sanitizer发现, 不影响实际写入文件的值和最后的结果.

      可以通过修改 CMakeLists.txt 的 target_compile_optionstarget_link_libraries 部分去除 -fsanitize=undefined 以隐藏报错, 或者可以把代码中的 char 修改为 unsigned char, 但是都没必要.

      This post has received 1 vote up.
      • This reply was modified 1 year, 7 months ago by aparaburu.
    • #17470 Score: 0
      IILKA
      Participant

      这个runtime error好像必须得解决, 比较合理的方法是把char 改为 unsigned char。
      至于渲染出来是黑色,可能原因是triangle.hpp 里的rayTriangleIntersect 没有写对,参数要每次都更新。

Viewing 4 reply threads
  • You must be logged in to reply to this topic.