Error while decoding a material


#1

Hello,

I am loading a material asset file (note that this material has been created from the built-in standard shader and then saved into an asset file) but I get this warning while decoding it:

Unknown version. Unable to deserialize.
		 in static bs::UINT32 bs::RTTIPlainType<bs::MaterialParamsRTTI::MaterialParam>::fromMemory(MaterialParamsRTTI::MaterialParam &, char *) [.../bsf/Source/Foundation/bsfCore/Private/RTTI/BsMaterialParamsRTTI.h:513]

Then my program crashes.

Signal: SIGSEGV (signal SIGSEGV: invalid address (fault address: 0x7fd9dda1eb70))
A fatal error occurred and the program has to terminate!
  - Error: Segmentation fault
  - Description: Received fatal signal
  - In function: 
  - In file: :0

Stack trace: 
0) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::CrashHandler::getStackTrace[abi:cxx11]()+0x59 [0x7fd482602559]
1) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::CrashHandler::logErrorAndStackTrace(std::__cxx11::basic_string<char, std::char_traits<char>, bs::StdAlloc<char, bs::GenAlloc> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, bs::StdAlloc<char, bs::GenAlloc> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, bs::StdAlloc<char, bs::GenAlloc> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, bs::StdAlloc<char, bs::GenAlloc> > const&, unsigned int) const+0x1b0 [0x7fd4825ebaf0]
2) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::CrashHandler::reportCrash(std::__cxx11::basic_string<char, std::char_traits<char>, bs::StdAlloc<char, bs::GenAlloc> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, bs::StdAlloc<char, bs::GenAlloc> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, bs::StdAlloc<char, bs::GenAlloc> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, bs::StdAlloc<char, bs::GenAlloc> > const&, unsigned int) const+0x4f [0x7fd48260213f]
3) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::signalHandler(int, siginfo_t*, void*)+0x1b3 [0x7fd4826020a3]
4) /usr/lib/libc.so.6: +0x37e00 [0x7fd48074de00]
5) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::MaterialParamsBase::getParamData(std::__cxx11::basic_string<char, std::char_traits<char>, bs::StdAlloc<char, bs::GenAlloc> > const&, bs::MaterialParamsBase::ParamType, bs::GpuParamDataType, unsigned int, bs::MaterialParamsBase::ParamData const**) const+0xd1 [0x7fd4828d9ce1]
6) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::Material::setParams(std::shared_ptr<bs::MaterialParams> const&)+0x57d [0x7fd48284febd]
7) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::MaterialRTTI::onDeserializationEnded(bs::IReflectable*, bs::SerializationContext*)+0x93 [0x7fd482619023]
8) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: +0xfdafcd [0x7fd4825aefcd]
9) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::BinarySerializer::decodeEntry(std::shared_ptr<bs::DataStream> const&, unsigned long, std::shared_ptr<bs::IReflectable> const&)+0x8d9 [0x7fd4825ac1b9]
10) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::BinarySerializer::decode(std::shared_ptr<bs::DataStream> const&, unsigned int, bs::SerializationContext*)+0x5a6 [0x7fd4825ab6b6]
11) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::Resources::loadFromDiskAndDeserialize(bs::Path const&, bool)+0x41f [0x7fd4828355ff]
12) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::Resources::loadCallback(bs::Path const&, bs::TResourceHandle<bs::Resource, false>&, bool)+0x59 [0x7fd482835129]
13) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::Resources::loadInternal(bs::UUID const&, bs::Path const&, bool, bs::Flags<bs::ResourceLoadFlag, unsigned int>)+0xf62 [0x7fd4828343b2]
14) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::Resources::load(bs::Path const&, bs::Flags<bs::ResourceLoadFlag, unsigned int>)+0x320 [0x7fd482833270]
15) test/cmake-build-debug-clang/bin/x64/Debug/libEditorCore.so: +0x6c4940 [0x7fd483a97940]
16) test/cmake-build-debug-clang/bin/x64/Debug/libEditorCore.so: +0x6cad4d [0x7fd483a9dd4d]
17) test/cmake-build-debug-clang/bin/x64/Debug/libEditorCore.so: std::function<void ()>::operator()() const+0x3e [0x7fd48397d7be]
18) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::TaskScheduler::runTask(std::shared_ptr<bs::Task>)+0x42 [0x7fd482562742]
19) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: void std::__invoke_impl<void, void (bs::TaskScheduler::*&)(std::shared_ptr<bs::Task>), bs::TaskScheduler*&, std::shared_ptr<bs::Task>&>(std::__invoke_memfun_deref, void (bs::TaskScheduler::*&)(std::shared_ptr<bs::Task>), bs::TaskScheduler*&, std::shared_ptr<bs::Task>&)+0xa7 [0x7fd482568fd7]
20) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: std::__invoke_result<void (bs::TaskScheduler::*&)(std::shared_ptr<bs::Task>), bs::TaskScheduler*&, std::shared_ptr<bs::Task>&>::type std::__invoke<void (bs::TaskScheduler::*&)(std::shared_ptr<bs::Task>), bs::TaskScheduler*&, std::shared_ptr<bs::Task>&>(void (bs::TaskScheduler::*&)(std::shared_ptr<bs::Task>), bs::TaskScheduler*&, std::shared_ptr<bs::Task>&)+0x47 [0x7fd482568eb7]
21) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: void std::_Bind<void (bs::TaskScheduler::*(bs::TaskScheduler*, std::shared_ptr<bs::Task>))(std::shared_ptr<bs::Task>)>::__call<void, , 0ul, 1ul>(std::tuple<>&&, std::_Index_tuple<0ul, 1ul>)+0x75 [0x7fd482568e45]
22) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: void std::_Bind<void (bs::TaskScheduler::*(bs::TaskScheduler*, std::shared_ptr<bs::Task>))(std::shared_ptr<bs::Task>)>::operator()<, void>()+0x33 [0x7fd482568d83]
23) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: std::_Function_handler<void (), std::_Bind<void (bs::TaskScheduler::*(bs::TaskScheduler*, std::shared_ptr<bs::Task>))(std::shared_ptr<bs::Task>)> >::_M_invoke(std::_Any_data const&)+0x1d [0x7fd4825689dd]
24) test/cmake-build-debug-clang/bin/x64/Debug/libEditorCore.so: std::function<void ()>::operator()() const+0x3e [0x7fd48397d7be]
25) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: bs::PooledThread::run()+0x12c [0x7fd48256a22c]
26) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: void std::__invoke_impl<void, void (bs::PooledThread::*&)(), bs::PooledThread*&>(std::__invoke_memfun_deref, void (bs::PooledThread::*&)(), bs::PooledThread*&)+0x71 [0x7fd48256c6a1]
27) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: std::__invoke_result<void (bs::PooledThread::*&)(), bs::PooledThread*&>::type std::__invoke<void (bs::PooledThread::*&)(), bs::PooledThread*&>(void (bs::PooledThread::*&)(), bs::PooledThread*&)+0x32 [0x7fd48256c5d2]
28) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: void std::_Bind<void (bs::PooledThread::*(bs::PooledThread*))()>::__call<void, , 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>)+0x50 [0x7fd48256c570]
29) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: void std::_Bind<void (bs::PooledThread::*(bs::PooledThread*))()>::operator()<, void>()+0x33 [0x7fd48256c4f3]
30) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: void std::__invoke_impl<void, std::_Bind<void (bs::PooledThread::*(bs::PooledThread*))()>>(std::__invoke_other, std::_Bind<void (bs::PooledThread::*(bs::PooledThread*))()>&&)+0x1d [0x7fd48256c4ad]
31) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: std::__invoke_result<std::_Bind<void (bs::PooledThread::*(bs::PooledThread*))()>>::type std::__invoke<std::_Bind<void (bs::PooledThread::*(bs::PooledThread*))()>>(std::_Bind<void (bs::PooledThread::*(bs::PooledThread*))()>&&)+0x1d [0x7fd48256c43d]
32) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: _ZNSt6thread8_InvokerISt5tupleIJSt5_BindIFMN2bs12PooledThreadEFvvEPS4_EEEEE9_M_invokeIJLm0EEEEDTclsr3stdE8__invokespcl10_S_declvalIXT_EEEEESt12_Index_tupleIJXspT_EEE+0x25 [0x7fd48256c415]
33) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: std::thread::_Invoker<std::tuple<std::_Bind<void (bs::PooledThread::*(bs::PooledThread*))()> > >::operator()()+0x15 [0x7fd48256c3e5]
34) test/cmake-build-debug-clang/bin/x64/Debug/libbsf.so.1: std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::_Bind<void (bs::PooledThread::*(bs::PooledThread*))()> > > >::_M_run()+0x19 [0x7fd48256c1d9]
35) /usr/lib/libstdc++.so.6: +0xbc063 [0x7fd480b37063]
36) /usr/lib/libpthread.so.0: +0x7a9d [0x7fd47f9b0a9d]
37) /usr/lib/libc.so.6: clone+0x43 [0x7fd480811b23]
Signal: SIGINT (signal SIGINT)
Signal: SIGSEGV (unknown crash reason)

Process finished with exit code 11

First time I have a look into bsf serialization so I am a little bit confused. Any idea what my be happening ?


#2

So I narrowed down the problem a little. onDeserializationEnded calls Material::setParams which calls MaterialParamsBase::getParamData. Then we lookup for the gEmissiveColor param in the mParamLookup lookup table which seem to be there. But the index of this parameter is wrong.

auto iter_find = mParamLookup.find( name );
if( iter_find == mParamLookup.end() )
{
	return GetParamResult::NotFound;
}

UINT32 index = iter_find->second;  // index: 873468128
const ParamData& param = mParams[index]; // bad access here

#3

Thanks, I’ve managed to reproduce and resolve the issue. It should be working fine on latest master.


#4

Works like a charm ! Thanks.