Page 1 of 1

wxNativePixelData assert on cocoa

Posted: Wed Dec 19, 2012 2:47 pm
by bcteh
Hi,

For wx 2.94, when used
wxNativePixelData data(bmp);

It cause below assert error, It is safe to comment out this assert message at ../../src/osx/core/bitmap.cpp(380) ?
I didn't saw any difference at my application, if i just ignore this message.

../../src/osx/core/bitmap.cpp(380): assert "m_rawAccessCount == 0" failed in BeginRawAccess().
Collecting stack trace information, please wait...../../src/osx/core/bitmap.cpp(401): assert "m_rawAccessCount == 1" failed in EndRawAccess().

It work on window and linux.

Re: wxNativePixelData assert on cocoa

Posted: Thu Dec 20, 2012 3:08 am
by doublemax
Ignoring asserts is usually not a good idea. But without seeing code it's impossible to tell what causes it.

Re: wxNativePixelData assert on cocoa

Posted: Sun Dec 23, 2012 11:44 am
by bcteh
Thank for advices.

I check on wxwidgets source, only found m_rawAccessCount variable on osx/core/bitmaps.cpp
It assign m_rawAccessCount = 0 on Init();
Increase on BeginRawAccess() and decrease on EndRawAccess()

When declare wxNativePixelData xxx(bmp);
the flow go to BeginRowAccess.
May be that is a bug, i didn't see others place for assigning this variable.
For my temporary solution, i just comment it :oops:

Code: Select all

void *wxBitmapRefData::BeginRawAccess()
{
    wxCHECK_MSG( IsOk(), NULL, wxT("invalid bitmap") ) ;
    wxASSERT( m_rawAccessCount == 0 ) ;
#ifndef __WXOSX_IPHONE__
    wxASSERT_MSG( m_pictHandle == NULL && m_iconRef == NULL ,
        wxT("Currently, modifing bitmaps that are used in controls already is not supported") ) ;
#endif
    ++m_rawAccessCount ;

    // we must destroy an existing cached image, as
    // the bitmap data may change now
    if ( m_cgImageRef )
    {
        CGImageRelease( m_cgImageRef ) ;
        m_cgImageRef = NULL ;
    }

    return m_memBuf.GetData() ;
}

void wxBitmapRefData::EndRawAccess()
{
    wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ;
    wxASSERT( m_rawAccessCount == 1 ) ;

    --m_rawAccessCount ;
}

Re: wxNativePixelData assert on cocoa

Posted: Sun Dec 23, 2012 12:09 pm
by doublemax
Actually i meant your code. Somehow you manage to get the access counter out of sync.