libretro / mgba

mGBA Game Boy Advance Emulator
https://mgba.io/
Mozilla Public License 2.0
68 stars 73 forks source link

Fix building in debug mode #151

Closed hhromic closed 5 years ago

hhromic commented 5 years ago

After the recent color correction addition in PR #150 (cc @jdgleaver), when building in debug mode, i.e. make DEBUG=1, the build fails with the following error:

src/platform/libretro/libretro.c: In function ‘_initColorCorrection’:
src/platform/libretro/libretro.c:127:39: error: initializer element is not constant
  static const float displayGammaInv = 1.0f / targetGamma;
                                       ^~~~
src/platform/libretro/libretro.c:129:33: error: initializer element is not constant
  static const float rgbMaxInv = 1.0f / rgbMax;
                                 ^~~~

According to this answer, the problem is that "Const-qualified objects (of any type) are not constants in C language terminology. They cannot be used in initializers of objects with static storage duration, regardless of their type.".

The solution as the same answer points out is to simply use #defines as done in this PR. I hope you are okay with my chosen names for these defines.

Note: his error only shows on debug builds because the compiler is configured to not perform any optimisation with -O0 and the error is not silent anymore.

jdgleaver commented 5 years ago

@hhromic Ah, good catch!

I took this from my colour correction stuff in the gambatte core - which of course is C++, so the values really were constant, and there were no errors. I just didn't notice the issue here (should have tested the debug build!)

Thanks for fixing this. The new defines are absolutely fine,

hhromic commented 5 years ago

No problem, happy to help! I was casually making a debug build to sort out a crash I'm getting with this core and stumbled upon this error.

Thanks to you too for the nice color correction implementation, games look much better indeed!