wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
tracyma
In need of some credit
In need of some credit
Posts: 5
Joined: Mon Nov 14, 2022 8:25 am

wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by tracyma »

after c++ exception been disabled globally with,

Code: Select all

string(REGEX REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
add_definitions(-D_HAS_EXCEPTIONS=0) # for STL
my app crashs when launch,
call stack shows `wxApp::GetTraitsIfExists()` returned invalid value 0x0000000000000001

Code: Select all

/* static */
wxFontMapperBase *wxFontMapperBase::Get()
{
    if ( !sm_instance )
    {
        wxAppTraits *traits = wxApp::GetTraitsIfExists();
        // !!! crash here, value of traits is 0x0000000000000001
        if ( traits )
        {
            sm_instance = traits->CreateFontMapper();

            wxASSERT_MSG( sm_instance,
                            wxT("wxAppTraits::CreateFontMapper() failed") );
        }

        if ( !sm_instance )
        {
            // last resort: we must create something because the existing code
            // relies on always having a valid font mapper object
            sm_instance = (wxFontMapper *)new wxFontMapperBase;
        }
    }

    return (wxFontMapperBase*)sm_instance;
}
and i use the wx installed with vcpkg
any idea? TIA!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by ONEEYEMAN »

Hi,
Don't use vcpkg - it's been proven to have some unexplainable bugs.
Get the sources, build it yourself and check with minimal sample.

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4182
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by PB »

BTW, is wxWidgets aware that you are not using exceptions, i.e., did you build it with wxUSE_EXCEPTIONS set to OFF?

Another build issue is also possible, did you try also with the minimal C++ and CMake code?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by ONEEYEMAN »

@PB,
I take he did not build the library, but used an installed one from vcpkg repo.

That's why I suggested to build the library. ;-)

Thank you.
tracyma
In need of some credit
In need of some credit
Posts: 5
Joined: Mon Nov 14, 2022 8:25 am

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by tracyma »

i'm trying integrate wx as cmake subdirectory, thank you!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by ONEEYEMAN »

Hi,
wxWidgets has CMake support.
All you need to do is download source code and use it to build the librar as part of your project.


Thank you.
BardicDream
In need of some credit
In need of some credit
Posts: 8
Joined: Sun Dec 11, 2022 12:16 am

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by BardicDream »

I am having the same issue where wxApp::GetTraitsIfExists() returns 0x0000000000000001.

I am using wxWidgets with cmake and Visual Studio 2019. As far as I know, I have not disabled exceptions, and I have built wxWidgets from source as a static library using the provided VS solution. I implemented the hello world example as provided on your website, and my project builds without errors or warnings. However, when attempting to run it, it throws an exception during initialization in the wxFontMapperBase::Get() method because it attempts to dereference the pointer to 0x1 which is returned by wxApp::GetTraitsIfExists().
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by doublemax »

BardicDream wrote: Sun Dec 11, 2022 12:54 am I am having the same issue where wxApp::GetTraitsIfExists() returns 0x0000000000000001.

I am using wxWidgets with cmake and Visual Studio 2019. As far as I know, I have not disabled exceptions, and I have built wxWidgets from source as a static library using the provided VS solution. I implemented the hello world example as provided on your website, and my project builds without errors or warnings. However, when attempting to run it, it throws an exception during initialization in the wxFontMapperBase::Get() method because it attempts to dereference the pointer to 0x1 which is returned by wxApp::GetTraitsIfExists().
Could you please repeat the test, but without cmake, using the wx-provided VS solution files for both the library and the "minimal" sample? (Don't use your own "hello world")
Use the source, Luke!
BardicDream
In need of some credit
In need of some credit
Posts: 8
Joined: Sun Dec 11, 2022 12:16 am

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by BardicDream »

minimal_vc16.sln solution builds and runs without problem.
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by doublemax »

BardicDream wrote: Tue Dec 13, 2022 3:24 am minimal_vc16.sln solution builds and runs without problem.
Thanks for testing. Just to be sure: you did build the 64bit configuration?
Use the source, Luke!
BardicDream
In need of some credit
In need of some credit
Posts: 8
Joined: Sun Dec 11, 2022 12:16 am

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by BardicDream »

Yes. I built the x64 debug configuration.
BardicDream
In need of some credit
In need of some credit
Posts: 8
Joined: Sun Dec 11, 2022 12:16 am

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by BardicDream »

Any idea what might be causing this? I reduced my own application to nothing more than any empty window which does nothing, not even a menu or status bar, but still get the error. I feel like it must be related to how cmake is building it, but don't have any idea where to start here. I have included my CMakeLists.txt below. The only thing I have included that was not in the examples I could find is the WIN32 tag when adding the executable, but that is required to get it to build, and according to the cmake documentation, the only thing it does is use WinMain as the entry point.

Code: Select all

cmake_minimum_required (VERSION 3.25)

project ("FXTestingEngine")

find_package (wxWidgets REQUIRED core base)

include (${wxWidgets_USE_FILE})

add_executable (
	FXTestingEngine WIN32
	"FXTestingEngine.h" "FXTestingEngine.cpp"
	"Application.h"     "Application.cpp"
	"Window.h"          "Window.cpp"
)

target_link_libraries (FXTestingEngine ${wxWidgets_LIBRARIES})
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by doublemax »

Can you zip and upload the whole project including the solution files that cmake generated? (Just the app, not the libs)
Use the source, Luke!
BardicDream
In need of some credit
In need of some credit
Posts: 8
Joined: Sun Dec 11, 2022 12:16 am

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by BardicDream »

doublemax wrote: Sun Dec 18, 2022 7:51 am Can you zip and upload the whole project including the solution files that cmake generated? (Just the app, not the libs)
I am not sure what solution files you are referring to. Cmake does not seem to generate any .sln files. At least, none that I can find in my project directory.
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxApp::GetTraitsIfExists() returns 0x0000000000000001 when C++ exception disabled

Post by doublemax »

BardicDream wrote: Mon Dec 19, 2022 5:41 am
doublemax wrote: Sun Dec 18, 2022 7:51 am Can you zip and upload the whole project including the solution files that cmake generated? (Just the app, not the libs)
I am not sure what solution files you are referring to. Cmake does not seem to generate any .sln files. At least, none that I can find in my project directory.
Cmake can create .sln files. What did you do instead?
Use the source, Luke!
Post Reply