bombomby / optick

C++ Profiler For Games
https://optick.dev
MIT License
2.95k stars 296 forks source link

Crash in ProfileServer.cpp: Server::Update() CRITICAL_SECTION(lock) #3

Closed floooh closed 9 years ago

floooh commented 9 years ago

Hi,

I've got brofiler working fine with a trivial 32-bit application, but get a crash in a more complex program in the first call of Server::Update() in ProfilerServer.cpp with "Access violation writing location 0x00000014.".

The crash happens in the CRITICAL_SECTION(lock) call, and it looks like the 'lock' object is not initialized (in fact it looks like the entire Server object is not initialized, everything is initialized to zero, and the Server::Server() constructor is never called:

brofiler_1

On the other hand, the constructor Core::Core() is called, and the CRITICAL_SECTION(lock) in Core::Update() works fine.

In the simpler program which works, the Server object is initialized when Server::Update() is called (although a breakpoint in the constructor is also never triggered, so this is a bit strange...):

brofiler_2

Any idea what's going on there, and how to fix or workaround?

Thanks! -Floh.

floooh commented 9 years ago

Update: I got it working by building ProfilerCore32 as static lib, and I had to use /SAFESEH:NO when linking my application (otherwise the linker step would complain). The trivial sample program worked with DLL and /SAFESEH on. Currently I have no idea why static-linking would make it work, I'm trying to find out more.

bombomby commented 9 years ago

Hello! Thank you for reporting this issue. I've looked through the code and have noticed possible race condition during initialization.

I've made a small fix: https://github.com/bombomby/brofiler/commit/2b6b2eec5c6bde9bc41e493511ea7da476990772

Please, let me know if it won't help. I will publish the new version in few days, however this fix is already available in sources.

P.S. Be careful with static-linking library. If your game consists of several (more than one) dll or exe using Brofiler API - it won't work correctly (well known situation when static variables will have unique copy for each dll unit). I've created static-linking build for the customer, who requested it ASAP and their game definitely links in one exe.

floooh commented 9 years ago

Thanks for the quick fix, I can't promise to look at this before Monday though, Thanks for the static-linking warning, we have all 'instrumented' code in a single exe so I think it should be ok :)