crashes - A heap has been corrupted error
crashes - A heap has been corrupted error
I noticed if I cancel the render too quickly normally before 50 passes 3dsmax will crash and the compiler will show me the error about "a heap has been corrupted" with a pointer on Luxcore::Scene and critical error number C0000374. The problem will appear just if I cancel the render too quickly or hit the render too many times. By the way, after 100 passes or so, never happened.
Not sure if this is related or not but if I compile all the codes with the optimization /Ox switch the problem will be less likely to happen and most of the time I will get no error at all.
here is the actual error in the compiler that may be useful.
Not sure if this is related or not but if I compile all the codes with the optimization /Ox switch the problem will be less likely to happen and most of the time I will get no error at all.
here is the actual error in the compiler that may be useful.
Omid Ghotbi (TAO)
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Re: crashes - A heap has been corrupted error
You are deleting objects in the wrong order. You are deleting objects while they are still referenced by other objects ("config" is referenced by "session", etc.). They crash can or can not happen, it depends if the broken pointers are referencing memory that has been reused (for your process) or not.
Also the correct order is:
How do you create the scene object ? Are you using the RenderConfig::DeleteSceneOnExit() ?
Also the correct order is:
Code: Select all
delete session;
delete config;
delete &scene; // NOTE: see below, there may be more
Re: crashes - A heap has been corrupted error
I did not use DeleteSceneOnExit() function and changed the order of the delete session as you mention.Dade wrote: ↑Tue Nov 30, 2021 8:53 am You are deleting objects in the wrong order. You are deleting objects while they are still referenced by other objects ("config" is referenced by "session", etc.). They crash can or can not happen, it depends if the broken pointers are referencing memory that has been reused (for your process) or not.
Also the correct order is:
How do you create the scene object ? Are you using the RenderConfig::DeleteSceneOnExit() ?Code: Select all
delete session; delete config; delete &scene; // NOTE: see below, there may be more
Code: Select all
Delete &scene
I need to add this, the error does not always mean crash, sometimes I will see the error but 3dsmax will not crash and function normally so if I'm not in debug mode I can not notice that all the time, just when the crash happens.
Omid Ghotbi (TAO)
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Re: crashes - A heap has been corrupted error
That's how I create sessions, config, and scenes, in the middle pass the data to it, and then after stopping the session delete all unnecessary things and free up memory.
note: i did not use //scene.RemoveUnusedTextures(); because once a while it will remove the last texture that actually is in use. don't know why. a minor issue that I face.
Code: Select all
scene.RemoveUnusedImageMaps();
scene.RemoveUnusedMaterials();
scene.RemoveUnusedMeshes();
//scene.RemoveUnusedTextures();
scene.SetDeleteMeshData(true);
RenderConfig *config = RenderConfig::Create(renderConfigProp, &scene);
RenderSession *session = RenderSession::Create(config);
//const float iteration_time_seconds = m_rendering_stopwatch.GetElapsedTime() / 1000.0;
//TSTR msg;
//msg.printf(MaxSDK::GetResourceStringAsMSTR(IDS_RENDER_TIMER), iteration_time_seconds);
//m_rendering_logger.LogMessage(IRenderingLogger::MessageType::Info, msg);
prog->SetSceneStats(0, 0, 0, maxscene->NumChildren(), 0);
renderProgTitle = (L"Compile the kernels, can take up to 5 minutes, be patient");
prog->SetTitle(renderProgTitle);
// To avoid const_cast below, and possibility of notifiee from changing the value
BroadcastNotification(NOTIFY_PRE_RENDER, (void*)(RendParams*)&frp);
m_rendering_stopwatch.Reset();
m_rendering_stopwatch.Start();
session->Start();
DoRendering(session, prog, tobm);
session->Stop();
m_rendering_stopwatch.Stop();
const float iteration_time_seconds = m_rendering_stopwatch.GetElapsedTime() / 1000.0;
mprintf(L"\nLuxCore -> Render finished in %.2f seconds\n", iteration_time_seconds);
mflush();
BroadcastNotification(NOTIFY_POST_RENDER);
delete session;
delete config;
delete &scene;
GetCOREInterface()->EnableSceneRedraw();
// Resume undo, macro recorder, animation, auto backup, and maintain
SuspendAll Resume();
Omid Ghotbi (TAO)
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Re: crashes - A heap has been corrupted error
Sorry I think I miss the first part of the code.
Code: Select all
int MaxToLux::Render(TimeValue t, Bitmap *tobm, FrameRendParams &frp, HWND hwnd, RendProgressCallback *prog, ViewParams *vp)
{
if (renderingMaterialPreview)
{
renderPreview(tobm, prog);
return true;
}
else
{
//Scene *scene = NULL;
Scene *scene = Scene::Create();
//In the camera 'export' function we check for supported camera, return false if camera not supported.
if (!lxmCamera.exportCamera((float)atof(LensRadiusstr.ToCStr()), *scene, t))
{
return false;
}
renderFinal(*scene, t, tobm,frp, hwnd, prog, vp);
return true;
}
}
Omid Ghotbi (TAO)
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Re: crashes - A heap has been corrupted error
You may be passing scene by value (not by pointer), how is renderFinal() declared ?TAO wrote: ↑Tue Nov 30, 2021 5:49 pmCode: Select all
renderFinal(*scene, t, tobm,frp, hwnd, prog, vp);
Re: crashes - A heap has been corrupted error
I'm not sure, Here is the renderfinal.Dade wrote: ↑Tue Nov 30, 2021 7:12 pmYou may be passing scene by value (not by pointer), how is renderFinal() declared ?TAO wrote: ↑Tue Nov 30, 2021 5:49 pmCode: Select all
renderFinal(*scene, t, tobm,frp, hwnd, prog, vp);
Code: Select all
void MaxToLux::renderFinal(luxcore::Scene &scene, TimeValue t, Bitmap *tobm, FrameRendParams &frp, HWND hwnd, RendProgressCallback *prog, ViewParams *vp)
Omid Ghotbi (TAO)
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Last update information
viewtopic.php?p=34390#p34390
My Artstation https://www.artstation.com/omidghotbi
My Instagram https://www.instagram.com/omid.ghotbi
Re: crashes - A heap has been corrupted error
It should work, the argument is declared by reference.TAO wrote: ↑Tue Nov 30, 2021 8:25 pm I'm not sure, Here is the renderfinal.Code: Select all
void MaxToLux::renderFinal(luxcore::Scene &scene, TimeValue t, Bitmap *tobm, FrameRendParams &frp, HWND hwnd, RendProgressCallback *prog, ViewParams *vp)