A custom plugin is throwing an error on Win 7 [SOLVED]

Started by Dualnames, Sun 17/02/2019 11:10:11

Previous topic - Next topic

Dualnames

So apparently 2/3rds of the Primordia squad, are using WINDOWS 7. I compiled a plugin recently, and I send the files over and they had two errors.
Error 1:
MSCVR100d.dll is missing

and
Error 2: Script link failed: Runtime error: unresolved import 'DrawScreenEffect'

(That is a custom function of the plugin).

Anyhows, so Error 1, has been fixed I recompiled the plugin with Visual Studio 08, but Error 2 remains, I thought maybe I should rebuild all files of the game, and reupload, which is what I'm in the process of doing. I don't mind sharing the plugin, and/or it's full code.

http://primordia-game.com/Files0/agswavev2.rar

In fact here it is.

Code: AGS



#ifdef WIN32
#define WINDOWS_VERSION
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma warning(disable : 4244)
#endif

#if !defined(BUILTIN_PLUGINS)
#define THIS_IS_THE_PLUGIN
#endif

#include <stdlib.h>
#include <stdio.h>
//#include <string.h>
//#include <math.h>
//#include <stdint.h>

#if defined(PSP_VERSION)
#include <pspsdk.h>
#include <pspmath.h>
#include <pspdisplay.h>
#define sin(x) vfpu_sinf(x)
#endif

#include "plugin/agsplugin.h"

#if defined(BUILTIN_PLUGINS)
namespace agswave {
#endif

#if defined(__GNUC__)
inline unsigned long _blender_alpha16_bgr(unsigned long y) __attribute__((always_inline));
inline void calc_x_n(unsigned long bla) __attribute__((always_inline));
#endif

const unsigned int Magic = 0xBABE0000;
const unsigned int Version = 1;
const unsigned int SaveMagic = Magic + Version;
const float PI = 3.14159265f;

int screen_width = 640;
int screen_height = 360;
int screen_color_depth = 32;

IAGSEngine* engine;



// Imported script functions



int dY=0;
int tDy=0;
int direction=0;

void CastWave(int delayMax, int PixelsWide)
{
  tDy++;
  if (tDy >delayMax)
  {
    tDy=0;
    if (direction==0) dY++;
	if (direction==1) dY--;
	if ( (dY>PixelsWide && direction==0) || (dY<-PixelsWide && direction==1) ) 
	{
		if (direction==0){dY=PixelsWide;direction=1;}
		else {dY=-PixelsWide;direction=0;}
	}
  }


}





void DrawEffect(int sprite_a,int sprite_b,int id)
{
  int x, y;
  
  BITMAP* src_a = engine->GetSpriteGraphic(sprite_a);
  BITMAP* src_b = engine->GetSpriteGraphic(sprite_b);

  unsigned int** pixel_a = (unsigned int**)engine->GetRawBitmapSurface(src_a);
  unsigned int** pixel_b = (unsigned int**)engine->GetRawBitmapSurface(src_b);

  for (y = 0; y < screen_height; y++)
  {
    if (id==0) CastWave(2,1);
	if (id==1) CastWave(15,1);
	
    for (x = 0; x < screen_width; x++)
    {
	  unsigned int colorfromB = pixel_b[y][x];
	  int getX=x;
	  int getY=y;

	  if (id==0)
	  {
	  	  getX=x-(rand() % 2)-2;
		  getY=y+dY;
	  }
	  if (id==1)
	  {
	  	  getX=x;
		  getY=y+dY;
	  }
	  if (getX < 0) getX=0;
	  if (getX > screen_width-1) getX = screen_width-1;
	  if (getY > screen_height-1) getY = screen_height-1;
	  if (getY < 0) getY = 0;
	  

	  pixel_a[getY][getX]=colorfromB;	  //
    }
  }
  engine->ReleaseBitmapSurface(src_a);
  engine->ReleaseBitmapSurface(src_b);

}


void RestoreGame(FILE* file)
{
  unsigned int Position = ftell(file);
  unsigned int DataSize;

  unsigned int SaveVersion = 0;
  fread(&SaveVersion, 4, 1, file);

  if (SaveVersion == SaveMagic)
  {
    fread(&DataSize, 4, 1, file);

    // Current version
   

    //fread(&g_DarknessLightLevel, 4, 1, file);
    
        
  }
  else if ((SaveVersion & 0xFFFF0000) == Magic)
  {
    // Unsupported version, skip it
    DataSize = 0;
    fread(&DataSize, 4, 1, file);

    fseek(file, Position + DataSize - 8, SEEK_SET);
  }
  else
  {
    // Unknown data, loading might fail but we cannot help it
    fseek(file, Position, SEEK_SET);
  }
}


void SaveGame(FILE* file)
{
  unsigned int StartPosition = ftell(file);

  fwrite(&SaveMagic, 4, 1, file);
  fwrite(&StartPosition, 4, 1, file); // Update later with the correct size


  //fwrite(&g_DarknessLightLevel, 4, 1, file);
  

  unsigned int EndPosition = ftell(file);
  unsigned int SaveSize = EndPosition - StartPosition;
  fseek(file, StartPosition + 4, SEEK_SET);
  fwrite(&SaveSize, 4, 1, file);

  fseek(file, EndPosition, SEEK_SET);
}


// ********************************************
// ************  AGS Interface  ***************
// ********************************************


void DrawScreenEffect(int sprite,int sprite_prev,int ide)
{	
	DrawEffect(sprite,sprite_prev,ide);
}

void AGS_EngineStartup(IAGSEngine *lpEngine)
{
  engine = lpEngine;
  
  if (engine->version < 13) 
    engine->AbortGame("Engine interface is too old, need newer version of AGS.");

 
  engine->RegisterScriptFunction("DrawScreenEffect", (void*)&DrawScreenEffect);

 
  
  engine->RequestEventHook(AGSE_PREGUIDRAW);
  engine->RequestEventHook(AGSE_PRESCREENDRAW);

#if defined(PSP_VERSION) || defined(ANDROID_VERSION) || defined(IOS_VERSION)
  engine->RequestEventHook(AGSE_SAVEGAME);
  engine->RequestEventHook(AGSE_RESTOREGAME);
#endif
}

void AGS_EngineShutdown()
{

}

int AGS_EngineOnEvent(int event, int data)
{
  if (event == AGSE_PREGUIDRAW)
  {
	 // WindEffect(g_Fx,g_Fy,g_Trans,g_RW,g_RH);
	  /*
    BITMAP* screen = engine->GetVirtualScreen();
	BITMAP* ParticleGraph = engine->GetSpriteGraphic(4322);
	//engine->BlitBitmap (100, 100, ParticleGraph, 0);
	engine->BlitSpriteTranslucent(100, 100, ParticleGraph,50);
	engine->ReleaseBitmapSurface(screen);
	//engine->MarkRegionDirty(0,0,screen_width,screen_height);
	engine->SetVirtualScreen(screen);*/
  }
  #if defined(PSP_VERSION) || defined(ANDROID_VERSION) || defined(IOS_VERSION)
  else if (event == AGSE_RESTOREGAME)
  {
    RestoreGame((FILE*)data);
  }
  else if (event == AGSE_SAVEGAME)
  {
    SaveGame((FILE*)data);
  }
#endif
  else if (event == AGSE_PRESCREENDRAW)
  {
    // Get screen size once here.
    //engine->GetScreenDimensions(&screen_width, &screen_height, &screen_color_depth);
	engine->UnrequestEventHook(AGSE_SAVEGAME);
	engine->UnrequestEventHook(AGSE_RESTOREGAME);
  }
  return 0;
}

int AGS_EngineDebugHook(const char *scriptName, int lineNum, int reserved)
{
  return 0;
}

void AGS_EngineInitGfx(const char *driverID, void *data)
{
}



#if defined(WINDOWS_VERSION) && !defined(BUILTIN_PLUGINS)

// ********************************************
// ***********  Editor Interface  *************
// ********************************************
//AGSFlashlight
const char* scriptHeader =
  "import void DrawScreenEffect(int sprite,int sprite_prev,int ide);\r\n";


IAGSEditor* editor;


LPCSTR AGS_GetPluginName(void)
{
  // Return the plugin description
  return "AGSWave";
}

int  AGS_EditorStartup(IAGSEditor* lpEditor)
{
  // User has checked the plugin to use it in their game

  // If it's an earlier version than what we need, abort.
  if (lpEditor->version < 1)
    return -1;

  editor = lpEditor;
  editor->RegisterScriptHeader(scriptHeader);

  // Return 0 to indicate success
  return 0;
}

void AGS_EditorShutdown()
{
  // User has un-checked the plugin from their game
  editor->UnregisterScriptHeader(scriptHeader);
}

void AGS_EditorProperties(HWND parent)
{
  // User has chosen to view the Properties of the plugin
  // We could load up an options dialog or something here instead
  MessageBoxA(parent, "AGSWave", "About", MB_OK | MB_ICONINFORMATION);
}

int AGS_EditorSaveGame(char* buffer, int bufsize)
{
  // We don't want to save any persistent data
  return 0;
}

void AGS_EditorLoadGame(char* buffer, int bufsize)
{
  // Nothing to load for this plugin
}

#endif


#if defined(BUILTIN_PLUGINS)
} // namespace agswave
#endif



I'm using 3.4.1 version of AGS
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Crimson Wizard

#1
Are you sure it loads up correctly? You may turn logging on: "log=1" under  "[misc]" section in acsetup.cfg and get log in "%USERPROFILE%/Saved Games/.ags/"

Quote from: Dualnames on Sun 17/02/2019 11:10:11
So apparently 2/3rds of the Primordia squad, are using WINDOWS 7. I compiled a plugin recently, and I send the files over and they had two errors.
Error 1:
MSCVR100d.dll is missing

I can tell two things here, first of all MSCVR100 is a part of Visual C++ Redistributable , probably 2010.

Secondly, which also may be relevant, the letter "d" in the name indicates that you were building plugin in Debug configuration. Assuming you may have done same thing under MSVS 2008, this could be reason plugin still is not loaded correctly. Programs and libs built in Debug config require different set of system libraries. Double check that you are building in Release configuration when sending plugin to your testers/players.

Snarky

I had the first problem with my Clipboard plugin (compiled with MSVS 2017 on a Win10 system). I think fixing it involved playing with the "Runtime library" compiler flags (Project Properties | Configuration Properties | C/C++ | Code Generation). Not sure whether it's /MT or /MD (/MTd or /MDd for debug) that ended up working.

Dualnames

@CrimsonWizard:
The dll works fine on my windows 8 pc, with no issues whatsoever.

I set it to "Release" now. Also the Error 1 is fixed, it came up initially, but compiling it under Visual Studio 2008 fixed it. But Error 2 has been present since the start. Could it be a lack of a NET Framework?


@Snarky:
Multi-threaded DLL <- this is where it's set.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Snarky

#4
Sorry, no clue about the second issue. The RegisterScriptHeader/Function calls look fine, and of course if it's working on your machine then there can't be something very wrong with the code itself.

I would be a bit nervous about the "compile on VS 2008" solution. As I understand the issue, it's that there's a version mismatch of the mscvr100.dll that the .dll was compiled against and the one present on the system running the game. Building on another version of VS may fix the problem for those particular users, but it would still potentially be there for someone else. The more robust solution is to ensure that the libraries it depends on are statically linked inside the .dll. So I think the setting should actually be set to "Multi-threaded (/MT)" rather than "Multi-threaded DLL (/MD)", even though it's a DLL you're building. (I could be wrong! I'm only half-remembering something I only half-understood in the first place. But at least, that's how it's set in my project.)

Dualnames

#5
The only reason it needed that dll was because I originally had it built it on VS 2010, I made a new project on VS 2008 and recompiled it, so it doesn't need the 2010s distributables, unfortunately the link error remains. Alright trying your other suggestion tho.

Edit: Same error.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Crimson Wizard

#6
Dualnames, have you tried checking the log?

Quote from: Dualnames on Sun 17/02/2019 13:15:48
The only reason it needed that dll was because I originally had it built it on VS 2010, I made a new project on VS 2008 and recompiled it, so it doesn't need the 2010s distributables

But it will still need 2008 redistributables. So building with /MT switch may make sense.
We are building AGS engine with /MT switch to prevent these problems.

EDIT: ok, I will try testing your plugin in a dummy game.

Dualnames

#7
I did set it to MT and it returned the same error. I will ask, it's not on my computer, so I'm talking with the artist, and trying to figure out stuff.

Working on getting that log for you.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Crimson Wizard

Hmm, well, it worked for me, but I have Visual Studio installed so that makes a difference usually in terms of dependencies.
The plugin you linked in the first post requires MSVCR90D.dll, which is a debug library (will probably be missing on most player's PCs).

Anyway, I managed to start the test game without problems, however it crashed when calling DrawScreenEffect.

Dualnames

Adventure Game Studio v3.4 Interpreter
Copyright (c) 1999-2011 Chris Jones and 2011-2018 others
ACI version 3.4.1.15

Installing exception handler
Initializing allegro
Initializing game data
Looking for the game data file
Located game data file: d:/THEWRE~1/NEWBUI~1/14/STRANG~1.EXE
Opened game data file: game28.dta
Game data version: 49
Compiled with: 3.4.1.15
Setting up game configuration
Setting up window
Initializing TTF renderer
Initializing mouse: number of buttons reported is 8
Checking memory
Data directory: d:/THEWRE~1/NEWBUI~1/14
Initializing audio vox
Audio vox found and initialized.
Initializing keyboard
Install timer
Initialize sound drivers
Sound settings: digital driver ID: 'AXA ' (0x41584120), MIDI driver ID: 'Auto' (0xffffffff)
Installed digital driver ID: 'AXA ' (0x41584120), MIDI driver ID: 'W32M' (0x5733324d)
Install exit handler
Initialize path finder library
Load game data
Game GUI version: 118
Requested script API: v3.4.1 (5), compat level: v3.4.0 (4)
Built library path: agswaves.dll
Plugin loading failed, trying built-in plugins...
No built-in plugin found. Plugin loading failed!
No placeholder functions for the plugin 'agswaves' found. The game might fail to load.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Dualnames

#10
http://primordia-game.com/Files0/Strangelando/agswavev5.rar

This is the 'proper' version of it (compiled with VS 2008) and the one we tested for the log above
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Dualnames

We got it working boys <3

edit: So what I changed was setting it to /MT (i sent the wrong file to the guy testing it) and all is well.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Crimson Wizard

Quote from: Dualnames on Sun 17/02/2019 13:46:59
We got it working boys <3

edit: So what I changed was setting it to /MT (i sent the wrong file to the guy testing it) and all is well.

Ok, that explains ).

Dualnames

So setting to /MT where Snarky explained, and getting it compiled under VS2008 solved both issues, marking this as solved. I feel really bad cause each time you suggest one thing first post, we do like 10 posts of dicking around, was the first post all along <3
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Crimson Wizard

Note that if you build with /MT you may probably use whatever MSVS as well, 2010, 2017.

Snarky

Quote from: Dualnames on Sun 17/02/2019 13:55:47
I feel really bad cause each time you suggest one thing first post, we do like 10 posts of dicking around, was the first post all along <3

Don't. I feel like when we get into these heavier technical issues, my guesses or advice is wrong more often than not, so I'm just happy it panned out this time around.

SMF spam blocked by CleanTalk