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

Fail to running test/simple/main.lua #193

Closed
ylme opened this issue Jul 22, 2024 · 10 comments
Closed

Fail to running test/simple/main.lua #193

ylme opened this issue Jul 22, 2024 · 10 comments

Comments

@ylme
Copy link
Contributor

ylme commented Jul 22, 2024

  • 更新 master 到最新
  • $ ./bin/mingw/debug/ant.exe test/simple/main.lua
  • 出现如下错误:
[2024-07-22 18:27:03.76][INFO ]( io )(D:/work/engine/ant/pkg/ant.compile_resource/subprocess.lua:68) D:/work/engine/ant/bin/mingw/debug/texturec.exe -f D:/work/engine/ant/pkg/ant.resources.test/sky/colorcube2x2.ktx -o D:/work/engine/ant/test/simple/res/windows-direct3d11/texture/colorcube2x2.texture_21a28db096e7137d02daaab46b3bc47f4d3b7d9c/main
.dds -q fastest --max 256 --linear -m
[2024-07-22 18:27:03.86][ERROR]( ant.resource_manager|resource ) compile failed: D:/work/engine/ant/pkg/ant.resources.test/sky/colorcube2x2.texture
----------------------------
Failed, error code:80000003
----------------------------
D:/work/engine/ant/bin/mingw/debug/texturec.exe -f D:/work/engine/ant/pkg/ant.resources.test/sky/colorcube2x2.ktx -o D:/work/engine/ant/test/simple/res/windows-direct3d11/texture/colorcube2x2.texture_21a28db096e7137d02daaab46b3bc47f4d3b7d9c/main.dds -q fastest --max 256 --linear -m
----------------------------

尝试定位:

  • 执行 $ gdb D:/work/engine/ant/bin/mingw/debug/texturec.exe
  • (gdb) set args D:/work/engine/ant/bin/mingw/debug/texturec.exe -f D:/work/engine/ant/pkg/ant.resources.test/sky/colorcube2x2.ktx -o D:/work/engine/ant/test/simple/res/windows-direct3d11/texture/colorcube2x2.texture_21a28db096e7137d02daaab46b3bc47f4d3b7d9c/main.dds -q fastest --max 256 --linear -m
  • (gdb) r
Starting program: D:\work\engine\ant\bin\mingw\debug\texturec.exe D:/work/engine/ant/bin/mingw/debug/texturec.exe -f D:/work/engine/ant/pkg/ant.resources.test/sky/colorcube2x2.ktx -o D:/work/engine/ant/test/simple/res/windows-direct3d11/texture/colorcube2x2.texture_21a28db096e7137d02daaab46b3bc47f4d3b7d9c/main.dds -q fastest --max 256 --linear
-m
[New Thread 23376.0x63d4]
[New Thread 23376.0x77a0]
[New Thread 23376.0x6370]
warning: 3rd/bimg/src/image.cpp(5278): ASSERT size == imageSize -> KTX: Image size mismatch 64 (expected 384).

Thread 1 received signal SIGTRAP, Trace/breakpoint trap.
bx::debugBreak () at 3rd/bx/src/debug.cpp:60
60

我对图形不怎么了解,求指导一下,出现这种情况如何处理呢?

PS: 还是用 mingw 来玩 ant 了,用 VS 编译出来的 texturec.exe 崩了后完全没有 core dump 文件(用的 debug),不如直接在 gdb 里面看崩的堆栈方便。

@cloudwu
Copy link
Contributor

cloudwu commented Jul 22, 2024

warning: 3rd/bimg/src/image.cpp(5278): ASSERT size == imageSize -> KTX: Image size mismatch 64 (expected 384).

这行信息,应该是几个月前的一个 bug ,早就解决了。问题应该和 bkaradzic/bimg#84 这个有关。我当初在公司的开发群里讨论过。但现在离职,所以没有记录了。

我刚才用 msvc 编译也没有重现。

考虑:

  1. 检查子模块是否都正确更新。
  2. 确保用 luamake -mode release tools 重新编译了工具。
  3. 把 test/simple 下的 res 和 .app 目录删除,保证没有过去版本的数据 cache 。

ps. msvc 应该可以在崩了后,立刻 vs attach 上去看。当然,我自己也用的 mingw 。

@ylme
Copy link
Contributor Author

ylme commented Jul 22, 2024

确认了,全部都用 release 去跑,是正常的。

然后在 debug 模式下,把 BX_ASSERT 这行 ASSERT 注释掉,重新编译一下 texturec 也能正常跑(删除了 res 和 .app 目录,用 debug 模式下的 texturec 重新转换)。

if (_imageContainer.m_ktx)
	{
		const uint32_t size = _imageContainer.m_numLayers == 1 && _imageContainer.m_cubeMap ? mipSize : mipSize * numSides;
		uint32_t imageSize  = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE);
		// BX_ASSERT(size == imageSize, "KTX: Image size mismatch %d (expected %d).", size, imageSize);
		BX_UNUSED(size, imageSize);

		offset += sizeof(uint32_t);
	}
}

是不是可以更新一下 colorcube2x2.ktx 这个资源,符合上面的 Image size 的 assert 判断就好啦?

@cloudwu
Copy link
Contributor

cloudwu commented Jul 22, 2024

我好像记得当初在内部群讨论过这个问题,这个 colorcube2x2.ktx 文件似乎有问题。@junjie020 看看当初的聊天记录,最后的结论是?

根据 https://registry.khronos.org/KTX/specs/1.0/ktxspec.v1.html

ktx 在保存 cubemap 时,imageSize 字段是每个 face 的 size ,而不是 6 个 face 的总 size 。所以在文件中应该记录 64 而不是 64*6 = 384 。不知道 colorcube2x2.ktx 是用什么工具生成的?

imageSize
For most textures imageSize is the number of bytes of pixel data in the current LOD level. This includes all array layers, all z slices, all faces, all rows (or rows of blocks) and all pixels (or blocks) in each row for the mipmap level. It does not include any bytes in mipPadding.
The exception is non-array cubemap textures (any texture where numberOfFaces is 6 and numberOfArrayElements is 0). For these textures imageSize is the number of bytes in each face of the texture for the current LOD level, not including bytes in cubePadding or mipPadding.

这个 ktx 文件符合过去版本的 texturec 的 (错误) 校验,但在 bkaradzic/bimg#63 之后,反而出错了。

@cloudwu
Copy link
Contributor

cloudwu commented Jul 22, 2024

btw, 我觉得 bimg 的工具实现对外部的文件数据输入做 assert 处理也不太对。应该输出 warning 或 error 信息。

@cloudwu
Copy link
Contributor

cloudwu commented Jul 23, 2024

这个 colorcube2x2.ktx 是用旧版本的 bimg 库生成的,需要使用 bkaradzic/bimg#82 这个 pr 之后的版本重新生成。

生成脚本已经不能正常工作了,我刚才稍微修了一下。但我觉得这个工具还需要完善,尤其是解析命令行的部分(不符合一般习惯):b9ca3ee

生成用的命令行如下:

bin/mingw/release/ant.exe tools/texture/main.lua '-faces=tools/texture/pkg/tools.texture/assets/simple_cubemap/right-green.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/left-yellow.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/top-white.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/bottom-black.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/forward-blue.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/backward-red.png' --outfile=colorcube2x2.ktx

@cloudwu
Copy link
Contributor

cloudwu commented Jul 23, 2024

@ylme 可以看看对不对。我本地测试应该是没问题的。

@ylme
Copy link
Contributor Author

ylme commented Jul 23, 2024

变成另一个报错了。

  • 更新前我的仓库是 2c2fabc
  • 然后 submodule 都是匹配的,然后执行 git clean -xfdgit submodule foreach --recursive git clean -xfd
  • 重新编译 luamakeluamake tools
  • 出现了昨天的报错,然后 git pull 然后 luamake
  • 执行 bin/mingw/debug/ant test/simple/main.lua ,出现新的报错。
[2024-07-23 12:32:04.87][DEBUG]( ant.window|window )(D:/work/engine/ant/pkg/ant.world/main.lua:747) world initialized
[2024-07-23 12:32:04.87][DEBUG]( ant.window|window )(D:/work/engine/ant/pkg/ant.world/main.lua:542) System changed.
[2024-07-23 12:32:04.87][DEBUG]( ant.window|window )(D:/work/engine/ant/pkg/ant.world/main.lua:573) System refreshed.
[2024-07-23 12:32:05.02][INFO ]( io )(...ork/engine/ant/pkg/ant.compile_resource/texture/util.lua:193) texture compile:
[2024-07-23 12:32:05.02][INFO ]( io )(D:/work/engine/ant/pkg/ant.compile_resource/subprocess.lua:68) D:/work/engine/ant/bin/mingw/debug/texturec.exe -f D:/work/engine/ant/pkg/ant.resources.test/sky/colorcube2x2.ktx -o D:/work/engine/ant/test/simple/res/windows-direct3d11/texture/colorcube2x2.texture_21a28db096e7137d02daaab46b3bc47f4d3b7d9c/main
.dds -q fastest --max 256 --linear -m
[2024-07-23 12:32:05.09][ERROR]( ant.resource_manager|resource ) build SH need cubemap texture
stack traceback:
        ( service:2 )
        [C]: in function 'error'
        ...ork/engine/ant/pkg/ant.compile_resource/texture/util.lua:228: in upvalue 'convert_image'
        .../engine/ant/pkg/ant.compile_resource/texture/compile.lua:23: in upvalue 'compile'
        .../engine/ant/pkg/ant.compile_resource/texture/convert.lua:27: in field '?'
        D:/work/engine/ant/pkg/ant.compile_resource/main.lua:58: in field 'compile_file'
        engine/console/io.lua:155: in upvalue 'COMPILE'
        engine/console/io.lua:63: in upvalue 'getresource'
        engine/console/io.lua:84: in upvalue 'getfile'
        engine/console/io.lua:93: in local 's'
        ( service:9 )
        [string "local name = ......"]:7: in upvalue 'call'
        [string "local name = ......"]:15: in field 'read'
        D:/work/engine/ant/pkg/ant.io/main.lua:7: in upvalue 'readall'
        D:/work/engine/ant/pkg/ant.io/main.lua:12: in field 'readall'
        D:/work/engine/ant/pkg/ant.serialize/main.lua:29: in field 'load'
        ...k/engine/ant/pkg/ant.resource_manager/thread/texture.lua:85: in upvalue 'loadTexture'
        ...k/engine/ant/pkg/ant.resource_manager/thread/texture.lua:238: in upvalue 'f'
  • 删除了 test/simple 目录下的 .app 和 res 目录,再次执行还是会出现上面的报错,用 debug 重新生成 colorcube2x2.ktx 然后覆盖过去,再次运行,也还是有上面的报错。
bin/mingw/debug/ant.exe tools/texture/main.lua '-faces=tools/texture/pkg/tools.texture/assets/simple_cubemap/right-green.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/left-yellow.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/top-white.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/bottom-black.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/forward-blue.png|tools/texture/pkg/tools.texture/assets/simple_cubemap/backward-red.png' --outfile=colorcube2x2.ktx

cloudwu added a commit that referenced this issue Jul 23, 2024
@cloudwu
Copy link
Contributor

cloudwu commented Jul 23, 2024

问题出在: 7c7f75f image.cpp 里打包 cubemap 时,传错了一个参数:倒数第二个参数应该是 true ,表示是一个 cubemap 。

我比较好奇的是,这并不是新引进的 bug ,但过去似乎也是用这段代码生成 colorcube2x2.ktx 的,为什么没有错 :(

@cloudwu
Copy link
Contributor

cloudwu commented Jul 23, 2024

blame 了一下,发现最初是对的,在 0cf05ec 里把 true 改成了 false 。@junjie020 这是手误还是有其它考虑?

@cloudwu cloudwu reopened this Jul 23, 2024
@ylme
Copy link
Contributor Author

ylme commented Jul 23, 2024

更新后,可以正常运行 simple 了。

因为 simple 例子就是会在外面显示个天空盒,瞎猜一下,从 bimp::imageAlloc 字面意思看,想生成一个 cube map 这里应该是要传为 true 吧。感觉原作者应该也不会设计一个接口是:生成一个 cube map 图像,却要把 _cubeMap 参数是 false

这个 issue 是不是可以关闭了?

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