← Back to team overview

kicad-developers team mailing list archive

Re: PATCH: fix double-free bug in 3D model viewer

 

Le 24/05/2016 à 09:29, Maciej Sumiński a écrit :
> Hi Cirilo,
> 
> I am wondering whether it really solves the problem. C++ standard ([1],
> 5.3.5.2) explicitly permits null pointer to be an argument for delete,
> so it should not crash there.
> 
> I am afraid the problem might be a bit more entangled. Mario & me have
> already noticed a few cases when an OpenGL context switch occurs before
> a destructor is called, and as the result OpenGL resources are being
> freed in a wrong OGL context.
> 
> It happens because wxWidgets does not permit setting OpenGL context when
> the parent window is invisible [2]. The second reason is delayed
> wxDialog destruction [3], so we cannot control when it exactly happens,
> and almost surely the destructor will be called when the window is
> already invisible. Due to that, the following might happen (Mario has
> discovered it):
> 
> 1. Display a modal dialog with a OpenGL canvas that uses a different context
> 2. Switch OpenGL context to the just created canvas
> 3. Close the modal dialog (it is not destructed yet)
> 4. Return to pcbnew, switch OpenGL context to GAL
> 5. The dialog destructor is called - officially you cannot switch the
> context now, as the dialog is invisible, so you are stuck in the GAL OGL
> context. Freeing OGL resources allocated in the dialog will fail,
> because it is a wrong context.
> 
> For the moment I do not have any good ideas how to solve the problem in
> a clear way.
> 
> Regards,
> Orson

Is it possible to remove the wxGLCanvas from the child windows list and to explicitly delete the
wxGLCanvas in the dialog Close event, instead of leave to the dialog dtor to delete this canvas?
A wxGLCanvas is not a managed window, so it should be possible to delete it explicitly outside the
dialog dtor.


> 
> 1. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf
> 2.
> http://docs.wxwidgets.org/stable/classwx_g_l_canvas.html#a9f9ab3909606484e717904064d4e7b4f
> 3.
> http://docs.wxwidgets.org/trunk/overview_windowdeletion.html#overview_windowdeletion_sequence
> 
> On 05/23/2016 11:35 PM, Cirilo Bernardo wrote:
>> The attached patch fixes bug #1572567 (crash on exit from
>> 3D Footprint Properties dialog). Since there was no check
>> before deleting m_ogl_3dmode, delete can be called on
>> NULL.
>>
>> - Cirilo


-- 
Jean-Pierre CHARRAS


References