project-navigation
Personal tools

Author Topic: Build of 2.5-dev fails to initialize com_genericPool before use on Darwin/Clang  (Read 9794 times)

Offline Jon_dArc

  • Squad Leader
  • ****
  • Posts: 134
    • View Profile
Bringing some stuff back home from IRC:

I had asked for guidance on whether the candidate solution was acceptable in general, whether only com_genericPool should receive the initialization-before-main treatment, and whether it should be in platform-specific code or if all platforms should initialize com_genericPool before main. I got a request for a demonstrative patch and gave the following:

Code: [Select]
@ -661,6 +661,11 @@ void R_ReallocateTexunitArray(gltexunit_t * texunit, int si
                r_state.active_texunit = texunit;
 }
 
+void really_init() __attribute__ ((constructor));
+void really_init(){
+  com_genericPool = Mem_CreatePool("ufomodel");
+}
+
 int main (int argc, char **argv)
 {
        Com_Printf("---- ufomodel " VERSION " ----\n");
@@ -673,7 +678,6 @@ int main (int argc, char **argv)
                Exit(1);
        }
 
-       com_genericPool = Mem_CreatePool("ufomodel");
        com_fileSysPool = Mem_CreatePool("ufomodel filesys");
        vid_modelPool = Mem_CreatePool("ufomodel model");
        vid_imagePool = Mem_CreatePool("ufomodel image");
(Which, of course, applies to src/tools/ufomodel/ufomodel.cpp—I was overzealous in not copying administrative debris)

Mattn suggested that in ufo some other systems needed to be working before memory pool initialization could occur, but I whipped up the following:

Code: [Select]
diff --git a/src/ports/macosx/osx_main.cpp b/src/ports/macosx/osx_main.cpp
index 74e177d..97d8cbe 100644
--- a/src/ports/macosx/osx_main.cpp
+++ b/src/ports/macosx/osx_main.cpp
@@ -54,6 +54,11 @@ static void SetWorkingDirectory ()
                Com_Printf("Failed to get path of main bundle\n");
 }
 
+void really_init() __attribute__ ((constructor));
+void really_init(){
+  com_genericPool = Mem_CreatePool("Generic");
+}
+
 /**
  * @brief The entry point for OSX server and client.
  *

which worked, at least as far as I could tell, without further issue.

~J