Previous 15994 Revisions Next

r8704 Wednesday 4th August, 2010 at 07:48:48 UTC by Miodrag Milanović
Fixed image error handling [thanks to ShimaPong]
[src/emu]devimage.c diimage.c image.c

src/emu/diimage.c
r8703r8704
271271void device_image_interface::clear_error()
272272{
273273    m_err = IMAGE_ERROR_SUCCESS;
274    if (m_err_message.len()==0)
274    if (m_err_message.len()!=0)
275275    {
276        //image_freeptr(image->dev, image->err_message);
277276        m_err_message.reset();
278277    }
279278}
r8703r8704
284283    error - returns the error text for an image
285284    error
286285-------------------------------------------------*/
286static const char *const messages[] =
287{
288   "",
289   "Internal error",
290   "Unsupported operation",
291   "Out of memory",
292   "File not found",
293   "Invalid image",
294   "File already open",
295   "Unspecified error"
296};
287297
288298const char *device_image_interface::error()
289299{
290    static const char *const messages[] =
291    {
292        NULL,
293        "Internal error",
294        "Unsupported operation",
295        "Out of memory",
296        "File not found",
297        "Invalid image",
298        "File already open",
299        "Unspecified error"
300    };
301
302    return m_err_message.len()==0 ? m_err_message : astring(messages[m_err]);
300    return (m_err_message.len()!=0) ? m_err_message.cstr() : messages[m_err];
303301}
304302
305303
src/emu/devimage.c
r8703r8704
345345
346346bool legacy_image_device_base::load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args)
347347{
348    image_error_t err;
349348    UINT32 open_plan[4];
350349    int i;
351350   bool softload = FALSE;
r8703r8704
360359    m_is_loading = TRUE;
361360
362361    /* record the filename */
363    err = set_image_filename(path);
364    if (err)
362    m_err = set_image_filename(path);
363    if (m_err)
365364        goto done;
366365
367366   /* Check if there's a software list defined for this device and use that if we're not creating an image */
r8703r8704
375374      for (i = 0; !m_file && open_plan[i]; i++)
376375      {
377376         /* open the file */
378         err = load_image_by_path(open_plan[i], path);
379         if (err && (err != IMAGE_ERROR_FILENOTFOUND))
377         m_err = load_image_by_path(open_plan[i], path);
378         if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND))
380379            goto done;
381380      }
382381   }
r8703r8704
392391
393392   /* did we fail to find the file? */
394393   if (!is_loaded() && !softload)
395   {
396      err = IMAGE_ERROR_FILENOTFOUND;
394   {     
395      m_err = IMAGE_ERROR_FILENOTFOUND;
397396      goto done;
398397   }
399398
r8703r8704
402401   m_create_args = create_args;
403402
404403   if (m_init_phase==FALSE) {
405      err = (image_error_t)finish_load();
406      if (err)
404      m_err = (image_error_t)finish_load();
405      if (m_err)
407406         goto done;
408407   }
409408    /* success! */
410409
411410done:
412    if (m_err) {
411    if (m_err!=0) {
413412      if (!m_init_phase)
414413      {
415414         if (machine->phase() == MACHINE_PHASE_RUNNING)
r8703r8704
434433         }
435434      }
436435   }
437   return err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS;
436   return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS;
438437}
439438
440439
r8703r8704
606605void *legacy_image_device_base::get_device_specific_call()
607606{
608607   return (void*) m_config.get_legacy_config_fct(DEVINFO_FCT_DEVICE_SPECIFIC);
609}
608}
No newline at end of file
src/emu/image.c
r8703r8704
225225         if (result)
226226         {
227227            /* retrieve image error message */
228            const char *image_err = image->error();
228            astring image_err = astring(image->error());
229229            const char *image_basename_str = image->basename();
230
231230            /* unload all images */
232231            image_unload_all(*machine);
233232
234233            fatalerror_exitcode(machine, MAMERR_DEVICE, "Device %s load (%s) failed: %s",
235234               image->image_config().devconfig().name(),
236235               image_basename_str,
237               image_err);
236               image_err.cstr());
238237         }
239238      }
240239      else
r8703r8704
267266         if (result)
268267         {
269268            /* retrieve image error message */
270            const char *image_err = image->error();
269            astring image_err = astring(image->error());
271270            const char *image_basename_str = image->basename();
272271
273272            /* unload all images */
r8703r8704
276275            fatalerror_exitcode(machine, MAMERR_DEVICE, "Device %s load (%s) failed: %s",
277276               image->image_config().devconfig().name(),
278277               image_basename_str,
279               image_err);
278               image_err.cstr());
280279         }
281280   }
282281

Previous 15994 Revisions Next


© 1998-2018 The MESS Team