changeset 2530:aacf3bd1cceb

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 16 May 2020 06:38:52 +0300
parents fddee4b6a427
children 24b32dbebe3d
files tests/plrtest.c tools/dumpmod.c tools/mod2wav.c tools/ppl.c
diffstat 4 files changed, 214 insertions(+), 137 deletions(-) [+]
line wrap: on
line diff
--- a/tests/plrtest.c	Sat May 16 06:11:53 2020 +0300
+++ b/tests/plrtest.c	Sat May 16 06:38:52 2020 +0300
@@ -106,7 +106,7 @@
     SDL_AudioSpec afmt;
     DMResource *file = NULL;
     char *inFilename = NULL;
-    int result = -1;
+    int res = -1;
     JSSModule *mod = NULL;
     JSSMixer *dev = NULL;
     JSSPlayer *plr = NULL;
@@ -116,63 +116,71 @@
 
     // Open the files
     if (inFilename == NULL)
-        result = dmf_open_stdio_stream(stdin, &file);
+        res = dmf_open_stdio_stream(stdin, &file);
     else
-        result = dmf_open_stdio(inFilename, "rb", &file);
+        res = dmf_open_stdio(inFilename, "rb", &file);
 
-    if (result != DMERR_OK)
+    if (res != DMERR_OK)
     {
-        fprintf(stderr, "Error opening input file '%s', #%d: %s\n",
-            inFilename, result, dmErrorStr(result));
-        return 1;
+        dmErrorMsg("Error opening input file '%s': %s\n",
+            inFilename, dmErrorStr(res));
+        goto exit;
     }
 
     // Initialize miniJSS
-    fprintf(stderr, "Initializing miniJSS\n");
+    printf("Initializing miniJSS\n");
     jssInit();
 
-
     // Read module file
-    dmMsg(1, "Reading file: %s\n", inFilename);
+    printf("Reading file: %s\n", inFilename);
 #ifdef JSS_SUP_XM
-    result = jssLoadXM(file, &mod, TRUE);
+    if (mod == NULL)
+    {
+        printf("* Trying XM...\n");
+        dmfreset(file);
+        if ((res = jssLoadXM(file, &mod, TRUE)) == DMERR_OK)
+        {
+            dmfreset(file);
+            res = jssLoadXM(file, &mod, FALSE);
+        }
+    }
 #endif
 #ifdef JSS_SUP_JSSMOD
-    dmfreset(file);
-    if (result != DMERR_OK)
+    if (mod == NULL)
     {
-        dmMsg(1, "* Trying JSSMOD ...\n");
-        result = jssLoadJSSMOD(file, &mod, TRUE);
+        printf("* Trying JSSMOD ...\n");
         dmfreset(file);
-        if (result == DMERR_OK)
-            result = jssLoadJSSMOD(file, &mod, FALSE);
-    }
-    else
-    {
-        dmMsg(2, "* Trying XM...\n");
-        result = jssLoadXM(file, &mod, FALSE);
+        if ((res = jssLoadJSSMOD(file, &mod, TRUE)) == DMERR_OK)
+        {
+            dmfreset(file);
+            res = jssLoadJSSMOD(file, &mod, FALSE);
+        }
     }
 #endif
     dmf_close(file);
 
     // Check for errors, we still might have some data tho
-    if (result != DMERR_OK)
+    if (res != DMERR_OK)
     {
-        dmErrorMsg("Error loading module file, %d: %s\n",
-            result, dmErrorStr(result));
+        dmErrorMsg(
+            "Error loading module file: %s\n",
+            dmErrorStr(res));
     }
 
     // Check if we have anything
     if (mod == NULL)
-        return 3;
-
+    {
+        res = dmError(DMERR_INIT_FAIL,
+            "Could not load module file.\n");
+        goto exit;
+    }
 
     // Try to convert it
-    if ((result = jssConvertModuleForPlaying(mod)) != DMERR_OK)
+    if ((res = jssConvertModuleForPlaying(mod)) != DMERR_OK)
     {
-        fprintf(stderr, "Could not convert module for playing, %d: %s\n",
-            result, dmErrorStr(result));
-        return 3;
+        dmErrorMsg("Could not convert module for playing: %s\n",
+            dmErrorStr(res));
+        goto exit;
     }
 
     // Initialize SDL audio
@@ -181,14 +189,15 @@
     afmt.channels = 2;
 
     // Initialize mixing device
-    fprintf(stderr, "Initializing miniJSS mixer with: %d, %d, %d\n",
+    printf("Initializing miniJSS mixer with: %d, %d, %d\n",
         JSS_AUDIO_S16, afmt.channels, afmt.freq);
 
     dev = jvmInit(JSS_AUDIO_S16, afmt.channels, afmt.freq, JMIX_AUTO);
     if (dev == NULL)
     {
-        fprintf(stderr, "jvmInit() returned NULL\n");
-        return 3;
+        res = dmError(DMERR_INIT_FAIL,
+            "jvmInit() returned NULL\n");
+        goto exit;
     }
 
     afmt.samples  = afmt.freq / 4;
@@ -196,20 +205,25 @@
     afmt.userdata = (void *) dev;
 
     // Open the audio device
-    fprintf(stderr, "Trying to init SDL with: %d, %d, %d\n",
+    
+    fprintf(stderr,
+        "Trying to init SDL with: %d, %d, %d\n",
         afmt.format, afmt.channels, afmt.freq);
 
     if (SDL_OpenAudio(&afmt, NULL) < 0)
     {
-        fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
-        return 4;
+        res = dmError(DMERR_INIT_FAIL,
+            "Couldn't open audio: %s\n",
+            SDL_GetError());
+        goto exit;
     }
 
     // Initialize player
     if ((plr = jmpInit(dev)) == NULL)
     {
-        fprintf(stderr, "jmpInit() returned NULL\n");
-        return 4;
+        res = dmError(DMERR_INIT_FAIL,
+            "jmpInit() returned NULL\n");
+        goto exit;
     }
 
     // Initialize playing
@@ -252,6 +266,7 @@
 
     printf("----------------------------------------------------\n");
 
+exit:
     SDL_LockAudio();
     SDL_PauseAudio(1);
     jmpClose(plr);
@@ -263,5 +278,5 @@
 
     jssClose();
 
-    return 0;
+    return res;
 }
--- a/tools/dumpmod.c	Sat May 16 06:11:53 2020 +0300
+++ b/tools/dumpmod.c	Sat May 16 06:38:52 2020 +0300
@@ -424,9 +424,9 @@
 
 int main(int argc, char *argv[])
 {
-    int result = -1, i;
     DMResource *file = NULL;
     JSSModule *mod = NULL;
+    int res = 0;
 
     dmInitProg("dumpmod", "miniJSS Module Viewer", "0.4", NULL, NULL);
     dmVerbosity = 0;
@@ -434,7 +434,10 @@
     // Parse arguments
     if (!dmArgsProcess(argc, argv, optList, optListN,
         argHandleOpt, argHandleFile, OPTH_BAILOUT))
-        exit(1);
+    {
+        res = 1;
+        goto exit;
+    }
 
     // Initialize miniJSS
     jssInit();
@@ -442,50 +445,60 @@
     // Open the file
     dmMsg(1, "Reading module file '%s'\n", optFilename);
     if (optFilename == NULL)
-        result = dmf_open_stdio_stream(stdin, &file);
+        res = dmf_open_stdio_stream(stdin, &file);
     else
-        result = dmf_open_stdio(optFilename, "rb", &file);
+        res = dmf_open_stdio(optFilename, "rb", &file);
 
-    if (result != DMERR_OK)
+    if (res != DMERR_OK)
     {
-        dmErrorMsg("Error opening input file '%s', #%d: %s\n",
-            optFilename, result, dmErrorStr(result));
-        return 1;
+        res = dmError(DMERR_FOPEN,
+            "Error opening input file '%s': %s\n",
+            optFilename, dmErrorStr(res));
+        goto exit;
     }
 
     // Read module file
     dmMsg(1, "Reading file: %s\n", optFilename);
 #ifdef JSS_SUP_XM
-    result = jssLoadXM(file, &mod, TRUE);
+    if (mod == NULL)
+    {
+        dmMsg(2, "* Trying XM...\n");
+        dmfreset(file);
+        if ((res = jssLoadXM(file, &mod, TRUE)) == DMERR_OK)
+        {
+            dmfreset(file);
+            res = jssLoadXM(file, &mod, FALSE);
+        }
+    }
 #endif
 #ifdef JSS_SUP_JSSMOD
-    dmfreset(file);
-    if (result != DMERR_OK)
+    if (mod == NULL)
     {
         dmMsg(1, "* Trying JSSMOD ...\n");
-        result = jssLoadJSSMOD(file, &mod, TRUE);
         dmfreset(file);
-        if (result == DMERR_OK)
-            result = jssLoadJSSMOD(file, &mod, FALSE);
-    }
-    else
-    {
-        dmMsg(2, "* Trying XM...\n");
-        result = jssLoadXM(file, &mod, FALSE);
+        if ((res = jssLoadJSSMOD(file, &mod, TRUE)) == DMERR_OK)
+        {
+            dmfreset(file);
+            res = jssLoadJSSMOD(file, &mod, FALSE);
+        }
     }
 #endif
     dmf_close(file);
 
     // Check for errors, we still might have some data tho
-    if (result != DMERR_OK)
+    if (res != DMERR_OK)
     {
-        dmErrorMsg("Error loading module file, %d: %s\n",
-            result, dmErrorStr(result));
+        dmErrorMsg("Error loading module file: %s\n",
+            dmErrorStr(res));
     }
 
     // Check if we have anything
     if (mod == NULL)
-        return 3;
+    {
+        res = dmError(DMERR_INIT_FAIL,
+            "Could not load module file.\n");
+        goto exit;
+    }
 
     // Print out information
     if (optViewGeneralInfo)
@@ -493,7 +506,7 @@
 
     if (optViewPatterns)
     {
-        for (i = 0; i < mod->npatterns; i++)
+        for (int i = 0; i < mod->npatterns; i++)
         if (mod->patterns[i] != NULL)
         {
             printf("\nPattern #%02x:\n", i);
@@ -507,7 +520,7 @@
         "ExtInstruments:\n"
         "---------------\n"
         );
-        for (i = 0; i < mod->nextInstruments; i++)
+        for (int i = 0; i < mod->nextInstruments; i++)
         if (mod->extInstruments[i] != NULL)
         {
             printf("#%02x: ", i + 1);
@@ -521,7 +534,7 @@
         "Instruments:\n"
         "------------\n"
         );
-        for (i = 0; i < mod->ninstruments; i++)
+        for (int i = 0; i < mod->ninstruments; i++)
         if (mod->instruments[i] != NULL)
         {
             printf("#%02x: ", i + 1);
@@ -529,9 +542,10 @@
         }
     }
 
+exit:
     // Free module data
     jssFreeModule(mod);
     jssClose();
 
-    return 0;
+    return res;
 }
--- a/tools/mod2wav.c	Sat May 16 06:11:53 2020 +0300
+++ b/tools/mod2wav.c	Sat May 16 06:38:52 2020 +0300
@@ -230,7 +230,7 @@
     JSSPlayer *plr = NULL;
     size_t bufLen = 1024*4, dataTotal, dataWritten, sampSize;
     Uint8 *dataBuf = NULL;
-    int result = -1;
+    int res;
 
     dmInitProg("mod2wav", "XM/JSSMOD to WAV renderer", "0.2", NULL, NULL);
     dmVerbosity = 1;
@@ -238,66 +238,80 @@
     // Parse arguments
     if (!dmArgsProcess(argc, argv, optList, optListN,
         argHandleOpt, argHandleFile, OPTH_BAILOUT))
-        return 1;
+    {
+        res = 1;
+        goto exit;
+    }
+
 
     // Check arguments
     if (optInFilename == NULL || optOutFilename == NULL)
     {
-        dmErrorMsg("Input or output file not specified. Try --help.\n");
-        return 1;
+        res = dmError(DMERR_INVALID_ARGS,
+            "Input or output file not specified. Try --help.\n");
+        goto exit;
     }
 
     // Initialize miniJSS
     jssInit();
 
     // Open the source file
-    if ((result = dmf_open_stdio(optInFilename, "rb", &inFile)) != DMERR_OK)
+    if ((res = dmf_open_stdio(optInFilename, "rb", &inFile)) != DMERR_OK)
     {
-        dmErrorMsg("Error opening input file '%s', %d: %s\n",
-            optInFilename, result, dmErrorStr(result));
+        dmErrorMsg("Error opening input file '%s': %s\n",
+            optInFilename, dmErrorStr(res));
         goto exit;
     }
 
     // Read module file
     dmMsg(1, "Reading file: %s\n", optInFilename);
 #ifdef JSS_SUP_XM
-    result = jssLoadXM(inFile, &mod, TRUE);
+    if (mod == NULL)
+    {
+        dmMsg(2, "* Trying XM...\n");
+        dmfreset(inFile);
+        if ((res = jssLoadXM(inFile, &mod, TRUE)) == DMERR_OK)
+        {
+            dmfreset(inFile);
+            res = jssLoadXM(inFile, &mod, FALSE);
+        }
+    }
 #endif
 #ifdef JSS_SUP_JSSMOD
-    dmfreset(inFile);
-    if (result != DMERR_OK)
+    if (mod == NULL)
     {
         dmMsg(1, "* Trying JSSMOD ...\n");
-        result = jssLoadJSSMOD(inFile, &mod, TRUE);
         dmfreset(inFile);
-        if (result == DMERR_OK)
-            result = jssLoadJSSMOD(inFile, &mod, FALSE);
-    }
-    else
-    {
-        dmMsg(2, "* Trying XM...\n");
-        result = jssLoadXM(inFile, &mod, FALSE);
+        if ((res = jssLoadJSSMOD(inFile, &mod, TRUE)) == DMERR_OK)
+        {
+            dmfreset(inFile);
+            res = jssLoadJSSMOD(inFile, &mod, FALSE);
+        }
     }
 #endif
     dmf_close(inFile);
 
     // Check for errors, we still might have some data tho
-    if (result != DMERR_OK)
+    if (res != DMERR_OK)
     {
-        dmErrorMsg("Error loading module file, %d: %s\n",
-            result, dmErrorStr(result));
+        dmErrorMsg("Error loading module file: %s\n",
+            dmErrorStr(res));
         goto exit;
     }
 
     // Check if we have anything
     if (mod == NULL)
+    {
+        res = dmError(DMERR_INIT_FAIL,
+            "Could not load module file.\n");
         goto exit;
+    }
 
     // Try to convert it
-    if ((result = jssConvertModuleForPlaying(mod)) != DMERR_OK)
+    if ((res = jssConvertModuleForPlaying(mod)) != DMERR_OK)
     {
-        dmErrorMsg("Could not convert module for playing, %d: %s\n",
-            result, dmErrorStr(result));
+        dmErrorMsg("Could not convert module for playing: %s\n",
+            dmErrorStr(res));
         goto exit;
     }
 
@@ -305,15 +319,17 @@
     dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO);
     if (dev == NULL)
     {
-        dmErrorMsg("jvmInit() returned NULL\n");
+        res = dmError(DMERR_INIT_FAIL,
+            "jvmInit() returned NULL\n");
         goto exit;
     }
 
     sampSize = jvmGetSampleSize(dev);
     if ((dataBuf = dmMalloc(bufLen * sampSize)) == NULL)
     {
-        dmErrorMsg("Could not allocate mixing buffer\n");
-        return 5;
+        res = dmError(DMERR_MALLOC,
+            "Could not allocate mixing buffer.\n");
+        goto exit;
     }
 
     dmMsg(1, "Using fmt=%d, bits=%d, channels=%d, freq=%d [%" DM_PRIu_SIZE_T " / sample]\n",
@@ -334,27 +350,31 @@
     jmpSetModule(plr, mod);
     if (optStartOrder >= 0)
     {
-        dmMsg(1, "Starting from song order #%d\n", optStartOrder);
-    } else
+        dmMsg(1, "Starting from song order #%d\n",
+            optStartOrder);
+    }
+    else
+    {
         optStartOrder = 0;
+    }
 
     jmpPlayOrder(plr, optStartOrder);
     jvmSetGlobalVol(dev, 150);
 
     if (optMuteOChannels > 0 && optMuteOChannels <= mod->nchannels)
     {
-        int i;
-        for (i = 0; i < mod->nchannels; i++)
+        for (int i = 0; i < mod->nchannels; i++)
             jvmMute(dev, i, TRUE);
+
         jvmMute(dev, optMuteOChannels - 1, FALSE);
     }
 
     // Open output file
     if ((outFile = fopen(optOutFilename, "wb")) == NULL)
     {
-        int err = dmGetErrno();
-        dmErrorMsg("Error opening output file '%s' #%d: %s.\n",
-            optInFilename, err, dmErrorStr(err));
+        res = dmGetErrno();
+        dmErrorMsg("Error opening output file '%s': %s.\n",
+            optInFilename, dmErrorStr(res));
         goto exit;
     }
 
@@ -380,12 +400,13 @@
         {
             jvmRenderAudio(dev, dataBuf, writeLen);
 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
-            jssEncodeSample16((Uint16 *)dataBuf, writeLen * optOutChannels, jsampSwapEndianess);
+            jssEncodeSample16((Uint16 *) dataBuf, writeLen * optOutChannels, jsampSwapEndianess);
 #endif
             dataWritten = fwrite(dataBuf, sampSize, writeLen, outFile);
             if (dataWritten < writeLen)
             {
-                dmErrorMsg("Error writing data!\n");
+                res = dmError(DMERR_FWRITE,
+                    "Error writing audio data!\n");
                 goto exit;
             }
             dataTotal += dataWritten;
@@ -398,7 +419,8 @@
     // Write the correct header
     if (fseek(outFile, 0L, SEEK_SET) != 0)
     {
-        dmErrorMsg("Error rewinding to header position!\n");
+        res = dmError(DMERR_FSEEK,
+            "Error rewinding to header position!\n");
         goto exit;
     }
 
@@ -417,5 +439,5 @@
     jssFreeModule(mod);
     jssClose();
 
-    return 0;
+    return res;
 }
--- a/tools/ppl.c	Sat May 16 06:11:53 2020 +0300
+++ b/tools/ppl.c	Sat May 16 06:38:52 2020 +0300
@@ -550,7 +550,7 @@
 {
     BOOL initSDL = FALSE, audioInit = FALSE;
     DMResource *file = NULL;
-    int result = -1;
+    int res = -1;
     BOOL muteState = FALSE;
 
     memset(&eng, 0, sizeof(eng));
@@ -573,10 +573,10 @@
         return 1;
     }
 
-    if ((result = dmf_open_stdio(optFilename, "rb", &file)) != DMERR_OK)
+    if ((res = dmf_open_stdio(optFilename, "rb", &file)) != DMERR_OK)
     {
         dmErrorMsg("Error opening file '%s': %s\n",
-            optFilename, dmErrorStr(result));
+            optFilename, dmErrorStr(res));
         return 1;
     }
 
@@ -586,38 +586,52 @@
     // Read module file
     dmMsg(1, "Reading file: %s\n", optFilename);
 #ifdef JSS_SUP_XM
-    result = jssLoadXM(file, &eng.mod, TRUE);
+    if (eng.mod == NULL)
+    {
+        dmMsg(2, "* Trying XM...\n");
+        dmfreset(file);
+        if ((res = jssLoadXM(file, &eng.mod, TRUE)) == DMERR_OK)
+        {
+            dmfreset(file);
+            res = jssLoadXM(file, &eng.mod, FALSE);
+        }
+    }
 #endif
 #ifdef JSS_SUP_JSSMOD
-    dmfreset(file);
-    if (result != DMERR_OK)
+    if (eng.mod == NULL)
     {
         dmMsg(1, "* Trying JSSMOD ...\n");
-        result = jssLoadJSSMOD(file, &eng.mod, TRUE);
         dmfreset(file);
-        if (result == DMERR_OK)
-            result = jssLoadJSSMOD(file, &eng.mod, FALSE);
-    }
-    else
-    {
-        dmMsg(2, "* Trying XM...\n");
-        result = jssLoadXM(file, &eng.mod, FALSE);
+        if ((res = jssLoadJSSMOD(file, &eng.mod, TRUE)) == DMERR_OK)
+        {
+            dmfreset(file);
+            res = jssLoadJSSMOD(file, &eng.mod, FALSE);
+        }
     }
 #endif
     dmf_close(file);
 
-    if (result != DMERR_OK)
+    // Check for errors, we still might have some data tho
+    if (res != DMERR_OK)
     {
         dmErrorMsg("Error loading module file: %s\n",
-            dmErrorStr(result));
+            dmErrorStr(res));
+        goto exit;
+    }
+
+    // Check if we have anything
+    if (eng.mod == NULL)
+    {
+        res = dmError(DMERR_INIT_FAIL,
+            "Could not load module file.\n");
         goto exit;
     }
 
     // Try to convert it
-    if ((result = jssConvertModuleForPlaying(eng.mod)) != DMERR_OK)
+    if ((res = jssConvertModuleForPlaying(eng.mod)) != DMERR_OK)
     {
         dmErrorMsg("Could not convert module for playing: %s\n",
-            dmErrorStr(result));
+            dmErrorStr(res));
         goto exit;
     }
 
@@ -625,7 +639,8 @@
     // Initialize SDL components
     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
     {
-        dmErrorMsg("Could not initialize SDL: %s\n",
+        res = dmError(DMERR_INIT_FAIL,
+            "Could not initialize SDL: %s\n",
             SDL_GetError());
         goto exit;
     }
@@ -639,7 +654,8 @@
     eng.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO);
     if (eng.dev == NULL)
     {
-        dmErrorMsg("jvmInit() returned NULL\n");
+        res = dmError(DMERR_INIT_FAIL,
+            "jvmInit() returned NULL\n");
         goto exit;
     }
 
@@ -650,7 +666,8 @@
         case JSS_AUDIO_S8:  eng.afmt.format = AUDIO_S8; break;
         case JSS_AUDIO_U8:  eng.afmt.format = AUDIO_U8; break;
         default:
-            dmErrorMsg("Unsupported audio format %d (could not set matching SDL format)\n",
+            res = dmError(DMERR_NOT_SUPPORTED,
+                "Unsupported audio format %d (could not set matching SDL format)\n",
                 optOutFormat);
             goto exit;
     }
@@ -664,7 +681,8 @@
     // Open the audio device
     if (SDL_OpenAudio(&eng.afmt, NULL) < 0)
     {
-        dmErrorMsg("Couldn't open SDL audio: %s\n",
+        res = dmError(DMERR_INIT_FAIL,
+            "Couldn't open SDL audio: %s\n",
             SDL_GetError());
         goto exit;
     }
@@ -673,7 +691,8 @@
     // Initialize player
     if ((eng.plr = jmpInit(eng.dev)) == NULL)
     {
-        dmErrorMsg("jmpInit() returned NULL\n");
+        res = dmError(DMERR_INIT_FAIL,
+            "jmpInit() returned NULL\n");
         goto exit;
     }
 
@@ -694,19 +713,19 @@
     {
         // Get font
         static const char *engineFontName = "pplfont.fnt";
-        result = dmf_open_memio(NULL, engineFontName, engineSetupFont, sizeof(engineSetupFont), &file);
-        if (result != DMERR_OK)
+        res = dmf_open_memio(NULL, engineFontName, engineSetupFont, sizeof(engineSetupFont), &file);
+        if (res != DMERR_OK)
         {
             dmErrorMsg("Error opening font file '%s': %s\n",
-                engineFontName, dmErrorStr(result));
+                engineFontName, dmErrorStr(res));
             goto exit;
         }
-        result = dmLoadBitmapFont(file, &font);
+        res = dmLoadBitmapFont(file, &font);
         dmf_close(file);
-        if (result != DMERR_OK)
+        if (res != DMERR_OK)
         {
             dmErrorMsg("Could not load font data from '%s': %s\n",
-                engineFontName, dmErrorStr(result));
+                engineFontName, dmErrorStr(res));
             goto exit;
         }
 
@@ -726,7 +745,9 @@
             //| SDL_WINDOW_HIDDEN
             )) == NULL)
         {
-            dmErrorMsg("Can't create an SDL window: %s\n", SDL_GetError());
+            res = dmError(DMERR_INIT_FAIL,
+                "Can't create an SDL window: %s\n",
+                SDL_GetError());
             goto exit;
         }
 
@@ -734,12 +755,17 @@
 
         if ((eng.renderer = SDL_CreateRenderer(eng.window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
         {
-            dmErrorMsg("Can't create an SDL renderer: %s\n", SDL_GetError());
+            res = dmError(DMERR_INIT_FAIL,
+                "Can't create an SDL renderer: %s\n",
+                SDL_GetError());
             goto exit;
         }
 
         if (!dmInitializeVideo())
+        {
+            res = DMERR_INIT_FAIL;
             goto exit;
+        }
 
         //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
         //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
@@ -983,5 +1009,5 @@
 
     jssClose();
 
-    return 0;
+    return res;
 }