Crash when calling dmBuffer::GetStream (Solved)

Im having a little problem at the moment, trying to pass a buffer of a mesh to my C++ extension.
My extensions call looks like this:

static int AddMeshFromGo(lua_State* L)
{
    DM_LUA_STACK_CHECK(L, 1);
    dmScript::LuaHBuffer *buffer = dmScript::CheckBuffer(L, 1);
    float r = (float)luaL_checknumber(L, 2);
    float g = (float)luaL_checknumber(L, 3);
    float b = (float)luaL_checknumber(L, 4);

    float *bytes = 0x0;
    uint32_t count = 0;
    uint32_t pcount = 0;
    uint32_t comp = 0;
    uint32_t stride = 0;
    
    dmBuffer::HBuffer hBuffer = buffer->m_Buffer;
    dmBuffer::Result pr = dmBuffer::GetStream(hBuffer, dmHashString64("position"), (void**)&bytes, &pcount, &comp, &stride);

And the lua script calling it looks like:

		local res_path = go.get(v.mesh, "vertices")
		local buf = resource.get_buffer(res_path)
        local meshid = extension.addmeshgo( buf, 1, 1, 1 )

When I run this, I get intermittent crashes. Sometimes on the second call of this, sometimes on the first call, and then sometime it doesnt crash.
The crash log is:

ERROR:CRASH: CALL STACK:

ERROR:CRASH:  0 0x7FF7F97A5330 dmCrash::GenerateCallstack D:\a\defold\defold\engine\crash\src\backtrace_win32.cpp:144

ERROR:CRASH:  1 0x7FF7F9B17D6C _seh_filter_exe /tmp/job14397124264486904960/minkernel/crts/ucrt/src/appcrt/misc/exception_filter.cpp:219

ERROR:CRASH:  2 0x7FF7F9B65A28 `__scrt_common_main_seh'::`1'::filt$0 d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:304

ERROR:CRASH:  3 0x7FF7F9ADF2D0 __C_specific_handler d:\agent\_work\4\s\src\vctools\crt\vcruntime\src\eh\riscchandler.cpp:290

ERROR:CRASH:  4 0x7FFC47493D80 __chkstk <unknown>:0

ERROR:CRASH:  5 0x7FFC4740E050 RtlFindCharInUnicodeString <unknown>:0

ERROR:CRASH:  6 0x7FFC47492E70 KiUserExceptionDispatcher <unknown>:0

ERROR:CRASH:  7 0x7FF7F981DE10 dmBuffer::GetStream D:\a\defold\defold\engine\dlib\src\dlib\buffer.cpp:583

ERROR:CRASH:  8 0x7FF7F966F690 AddMeshFromGo /tmp/job14397124264486904960/upload/fastpix/src/FastPixLib.cpp:83

ERROR:CRASH:  9 0x7FF7F97045DE lj_BC_FUNCC <unknown>:0

ERROR:CRASH: 10 0x7FF7F979C910 lua_pcall <unknown>:0

ERROR:CRASH: 11 0x7FF7F97CDFC0 dmScript::PCallInternal D:\a\defold\defold\engine\script\src\script.cpp:1386

ERROR:CRASH: 12 0x7FF7F981C760 dmGameObject::RunScript D:\a\defold\defold\engine\gameobject\src\gameobject\comp_script.cpp:138

ERROR:CRASH: 13 0x7FF7F981C950 dmGameObject::CompScriptUpdateInternal D:\a\defold\defold\engine\gameobject\src\gameobject\comp_script.cpp:236

ERROR:CRASH: 14 0x7FF7F97F99C0 dmGameObject::Update D:\a\defold\defold\engine\gameobject\src\gameobject\gameobject.cpp:2572

ERROR:CRASH: 15 0x7FF7F9860FE0 dmEngine::StepFrame D:\a\defold\defold\engine\engine\src\engine.cpp:1572

ERROR:CRASH: 16 0x7FF7F985C1E0 dmEngineUpdate D:\a\defold\defold\engine\engine\src\engine.cpp:2100

ERROR:CRASH: 17 0x7FF7F9861A00 dmEngine::RunLoop D:\a\defold\defold\engine\engine\src\engine_loop.cpp:83

ERROR:CRASH: 18 0x7FF7F97931E0 engine_main D:\a\defold\defold\engine\engine\src\engine_main.cpp:148

ERROR:CRASH: 19 0x7FF7F9ADEE84 __scrt_common_main_seh d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288

ERROR:CRASH: 20 0x7FFC45A126A0 BaseThreadInitThunk <unknown>:0

ERROR:CRASH: 21 0x7FFC4744DF90 RtlUserThreadStart <unknown>:0

ERROR:CRASH: 

INFO:CRASH: Successfully wrote Crashdump to file: C:\Users\dlannan\AppData\Roaming\Defold/_crash
ERROR:CRASH: CALL STACK:

ERROR:CRASH:  0 0x7FF7F981DE10 dmBuffer::GetStream D:\a\defold\defold\engine\dlib\src\dlib\buffer.cpp:583

ERROR:CRASH:  1 0x7FF7F966F690 AddMeshFromGo /tmp/job14397124264486904960/upload/fastpix/src/FastPixLib.cpp:83

ERROR:CRASH:  2 0x7FF7F97045DE lj_BC_FUNCC <unknown>:0

ERROR:CRASH:  3 0x7FF7F979C910 lua_pcall <unknown>:0

ERROR:CRASH:  4 0x7FF7F97CDFC0 dmScript::PCallInternal D:\a\defold\defold\engine\script\src\script.cpp:1386

ERROR:CRASH:  5 0x7FF7F981C760 dmGameObject::RunScript D:\a\defold\defold\engine\gameobject\src\gameobject\comp_script.cpp:138

ERROR:CRASH:  6 0x7FF7F981C950 dmGameObject::CompScriptUpdateInternal D:\a\defold\defold\engine\gameobject\src\gameobject\comp_script.cpp:236

ERROR:CRASH:  7 0x7FF7F97F99C0 dmGameObject::Update D:\a\defold\defold\engine\gameobject\src\gameobject\gameobject.cpp:2572

ERROR:CRASH:  8 0x7FF7F9860FE0 dmEngine::StepFrame D:\a\defold\defold\engine\engine\src\engine.cpp:1572

ERROR:CRASH:  9 0x7FF7F985C1E0 dmEngineUpdate D:\a\defold\defold\engine\engine\src\engine.cpp:2100

ERROR:CRASH: 10 0x7FF7F9861A00 dmEngine::RunLoop D:\a\defold\defold\engine\engine\src\engine_loop.cpp:83

ERROR:CRASH: 11 0x7FF7F97931E0 engine_main D:\a\defold\defold\engine\engine\src\engine_main.cpp:148

ERROR:CRASH: 12 0x7FF7F9ADEE84 __scrt_common_main_seh d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288

ERROR:CRASH: 13 0x7FFC45A126A0 BaseThreadInitThunk <unknown>:0

ERROR:CRASH: 14 0x7FFC4744DF90 RtlUserThreadStart <unknown>:0

ERROR:CRASH: 

INFO:CRASH: Successfully wrote MiniDump to file: 

Ive attached the crashdump too. Im kinda not really sure what to look for here, since it is happening in the getstream buffer call, and I think Im calling it correctly?
Line 83 in the cpp is the GetStream call. Because it doesnt return a response, I cant check that either.
_crash.zip (17.2 KB)

Any help or idea would be greatly appreciated.

Try
dmScript::CheckBufferUnpack

You should’t use m_Buffer

2 Likes

“You should’t use m_Buffer”

Oh. cool. I didnt know that Ive been using that in many places :slight_smile:
I’ll give that a try thanks.

@d954mas - Thanks very much for your assist.
It makes alot more sense now. I have been using CheckBuffer and not CheckBufferUnpack.
Really appreciate the fast help there. And now, I probably should revisit some of my extensions to repair them!!!
Thanks again!

2 Likes